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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Barrie Davidson

MrExcel MVP
Joined
Feb 10, 2002
Messages
2,330
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,
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
66,494
Office Version
  1. 365
Platform
  1. Windows
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
 

Forum statistics

Threads
1,186,160
Messages
5,956,272
Members
438,245
Latest member
bhavdip_mangukiya

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
Top