Find row and insert formula, skipping columns

  • Thread starter Thread starter Ray
  • Start date Start date
R

Ray

Hello ... I need some help building code to find a specified row and
insert a formula in every other column. The sheet is set up like
this:

Column C holds the value to be matched against
Column E is the first column to add the first formula, and then in
every other column out to Col BY (so E/G/I/etc).

The value to match will be hard-coded into the code itself ...

Any/all help is greatly appreciated...

Regards,
ray
 
Try something like this:

Private Sub TestMatching()
Dim sValue As String, dX As Double, dY As Double

sValue = "Text to find a match for" 'hardcoded thing you're
wanting to match. I'm assuming it's a string, but you can change it
to a number type if you want.

'loop through all populated rows in column C
For dX = 1 To ActiveSheet.UsedRange.Rows.Count
If Cells(dX, 3).Value = sValue Then
'if a match is found, loop through every other adjacent
column and then add the formula
For dY = 5 To 78 Step 2
Cells(dX, dY).Formula = "=C" & dX 'this formula
equals the value in column C. Change the formula to whatever you
need.
Next
End If
Next

MsgBox "All done"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top