Entering a number via a macro

jaypatel

Active Member
Joined
Nov 25, 2002
Messages
389
Hi,

I need a macro that says something like:

if cell g3= blank and then enter nothing in cell e3
if cell g4 is not blank then enter "4" in cell e4 etc

all the way through for rows 1-65536.

Basically if cell gx is blank then do nothing. if cell gx is not blank then enter the number 4 in ex (where x is the row number)

Jay
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Code:
Dim LastRow As Long

LastRow = Range("G65536").End(xlUp).Row
Range("G1:G" & LastRow).AutoFilter Field:=1, Criteria1:="<>"
Range("H1:H" & LastRow).SpecialCells(xlCellTypeVisible).Value = 4
Range("G1:G" & LastRow).AutoFilter

Best regards,
 
Upvote 0
Another macro:

Code:
Sub MyMacro()
    
    Dim cell As Range
    For Each cell In Range("G1:G65536")
        If Len(cell) > 0 Then cell.Offset(0, -2) = 4
    Next cell

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,024
Messages
6,122,729
Members
449,093
Latest member
Mnur

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