Select Case

rhmkrmi

Active Member
Joined
Aug 17, 2012
Messages
341
Office Version
  1. 365
Platform
  1. Windows
Hi there,

How can I use Select Case in VBA for a cell where the value is calculated based on a formula?

In cell A1 in Sheet 2, I have =IF(ISBLANK('Sheet 1'!A1),"","Check") and I need the Select Case in VBA to populate cell N in Sheet 2 with "Check" if A1 in Sheet 2 gets "Check" and if A1 in Sheet 2 gets "" from the formula in it, then N in Sheet 2 should also be null.

Thanks.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
VBA Code:
With Sheets("Sheet 2")
      .N=.[A1].Value
End With
 
Upvote 0
Thanks.

I added it into my code but it is not quite working:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range
Dim cell As Range
Dim rw As Long

Set rng = Intersect(Target, Range("A:A"))
If rng Is Nothing Then Exit Sub

With Sheets("Sheet2")
.N = .[A1].Value
End With

For Each cell In rng
rw = cell.Row
Select Case cell.Value
Case "Check"
Range(Cells(rw, "N"), Cells(rw, "N")) = "Check"
Case Else
Range(Cells(rw, "N"), Cells(rw, "N")) = ""
End Select
Next cell
End Sub

It finds a bug in " .N = .[A1].Value" and I also want range A and range N to be checked and populated.

If you could help with this, it would be great.

Thank you.
 
Upvote 0
How are the values in Sheet1 column A changed. By formula or by manual input?

Instead of VBA, why not just put in Sheet2 column N a formula :
Either : =A1
Or : the same formula as column A
 
Upvote 0
In Sheet 1 the data is entered manually.
This piece of data does not exist in Sheet 1 so I am trying to populate column N in Sheet 2 with this message if column A in Sheet 2 shows that there is data in column A in Sheet 1.
 
Upvote 0
So you want column N (Sheet2) to be the same as column A (Sheet2) ?
If so, see post #4.
 
Upvote 0
I want column N in Sheet 2 to be populated with "Check" if column A in Sheet 2 is populated with anything from the formula in it.

In my original post they are both "Check" but column A can have other formula in it too.
 
Upvote 0
Maybe in column N (Sheet2) : =IF(A1="Check",A1,"")

If that doesn't do it, some sample data would help.
 
Upvote 0
Yes it can work but I am trying not to use a formula in column N and have a macro do the job.
So, I need to populate column N cells in Sheet 2 with "Check" if the corresponding cell in column A in Sheet 1 is not blank.

Thank you.
 
Upvote 0
I also got this code works for me but I have to run it manually!
I need to automate it so that when any cell in range A1:A100 is populated, the corresponding cell in column N automatically gets populated with "Check" but I do not know how to do it.

Sub populateB()
For Each cel In Range("A1:A100")
If cel.Value <> "" Then cel.Offset(0, 14).Value = "Check"
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,803
Members
449,337
Latest member
BBV123

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