Command Button to change a Cell

Tech1_uk

New Member
Joined
Sep 22, 2018
Messages
17
Hi all,

I've set up a simple button to change a cell value from another cell,

Code is

VBA Code:
Private Sub CommandButton1_Click()

Sheets("Sheet1").Range("G6").Value = Sheets("Sheet2").Range("E5").Value

End Sub

Now I only want to change G6 if it matches a a set criteria, in this case "No" if it it then any other text then don't change the value.
Once this is working I then want to use the range G6:G25 to do the same

Any ideas?

Many thanks
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I've managed the first part but I can't repeat this over a range of cells

I'm using the following

VBA Code:
If Range("G6").Value = "No" Then Sheets("Sheet1").Range("G6").Value = Sheets("Sheet2").Range("E5").Value

For Cell G7 and onwards I'm having to repeat each line

Code:
If Range("G7").Value = "No" Then Sheets("Sheet1").Range("G7").Value = Sheets("Sheet2").Range("E5").Value

Has to be an easy way to do this ???
 
Upvote 0
VBA Code:
Dim c As Range
For Each c In Range("G7:G25")
    If c = "No" Then c = Sheets("Sheet2").Range("E5").Value
Next c
 
Upvote 0

Forum statistics

Threads
1,215,821
Messages
6,127,053
Members
449,356
Latest member
tstapleton67

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