It's getting late and i have a report due tomorrow

Castyel

New Member
Joined
Jul 8, 2012
Messages
21
is there a way to reference a cell with a known column but a changing row.

ie

For Each i In Range("S47:S50")
If i = 1 Then
For Each cell In Sheets("sheet1").Range(D?,F?,H?,G?) :confused:
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Wouldn't you want something like....

Rich (BB code):
For Each i In Range("S47:S50")
    If i = 1 Then
        For Each cell In Sheets("sheet1").Range(D?:G?)
.
.
.
        Next cell
    End If
Next i

I assume you'd need some type of code after the "IF i" to determine the "?" row value.
 
Last edited:
Upvote 0
my issue is more with how do I get VBA to work on the row I want I have tried ("D" & ActiveCell.Row) but I don't think it is using the row where i = 1 but the row that was active on the sheet when the macro was run
 
Upvote 0
Wouldn't this do the trick?


For Each cell In Sheets("sheet1").Range("D" & i & ":G" & i)

</pre>
 
Upvote 0
still does not seem to work it runs through and even when the cell is empty acts as if it wasn't


Code:
Sub manditory2()

        For Each i In Range("S47:S82") 
            If i = 1 Then 
                For Each cell In Sheets("sheet1").Range("D" & i) 
                    If IsEmpty("D" & i) Then 
                        MsgBox "Mandatory field not filled" 
                        Application.Goto cell 
                        Cancel = True 
                        Exit For 
                    End If 
                Next cell 
                
            End If 
       Next i
end sub
 
Upvote 0
My code still seem to look at D1 not which ever D on the row where i = 1.

Can some one please help it's midnight and I have to be at work in 7 hours
 
Upvote 0
Don't use Range for what you are doing, rather, use Cells (an alternate to Range that takes row and column arguments). For what you appear to be doing, something like this...

Code:
RowNumber = 8
For i = 4 To 7  ' the column numbers for Columns D, E, F and G
  If Cells(RowNumber, i).Value = "" Then
    MsgBox "Mandatory field not filled" 
    Application.Goto Cells(RowNumber, i) 
    Cancel = True 
    Exit For 
  End If
Next
 
Upvote 0
ok that sounds great but I'm a little tired as its 1 am here.
how does it search each row in column S to find the those that have a 1 to run what you have posted?

sorry if I don't make sense I have been building this report most of the day
 
Upvote 0
Also if I tell it as a test to run line 48 it picks up cells that have text in them as empty does that code work also for text or just values?
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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