Reference first row of same Column - For Each Cell

KlaasE

New Member
Joined
Nov 4, 2019
Messages
37
Hello,

I'm trying to create a For Each loop, where any cell that is not zero, will be changed to the date that is in row 1 of the same column.
So far I've come up with the following, but I can't seem to find the correct syntax for this seemingly simple problem:

VBA Code:
Sub ArrangeDates()

Dim Cell As Range
Dim ShipDate As Integer

For Each Cell In Range("B2:H50")

    If Cell.Value > 0 Then
      Cell.Value = //same column, row 1//
    End If
    Next Cell
End Sub

So for instance if C5 = 5, it should change to the value of C1, which is a (shipping) date.
I tried to format something with Cell.Column() or create a Dim as Integer to store the Cell column, but so far without succes.

I've attached a small example of the sheet I use it on (top) and the output I'd want (bottom).
Any suggestion or source would be appreciated.

Thank you!
 

Attachments

  • example.PNG
    example.PNG
    12 KB · Views: 10

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try
VBA Code:
Cell.Value = CDate(Cells(1, Cell.Column).Value)
 
Upvote 1
Solution

Forum statistics

Threads
1,224,813
Messages
6,181,111
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top