How to state ranges with Elseif in VBA?

Chucky3006

New Member
Joined
Jun 20, 2017
Messages
11
Good day

Is there anyone that can assist.....

I managed to get the code working for single cells but unable to get the code working for multiple cells.



Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("A6") = "" Then
Range("A6") = "=A1"
ElseIf Range("A1") = "" Then
Range("A6") = Me.Range("A6").Value
ElseIf Range("A1") = "NDO" Then
Range("A6") = Me.Range("A6").Value
ElseIf Range("A1") = "NDO" Then
Range("A6") = "NDO"
ElseIf Range("A1") = "" Then
Range("A6") = ""
End If
End Sub

Bassically what i think it should look like is:


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("A6:F6") = "" Then
Range("A6:F6") = Range("A1:F1")
ElseIf Range("A1:F1") = "" Then
Range("A6:F6") = Me.Range("A6:F6").Value
ElseIf Range("A1:F1") = "NDO" Then
Range("A6:F6") = Me.Range("A6:F6").Value
ElseIf Range("A1:F1") = "NDO" Then
Range("A6:F6") = "NDO"
ElseIf Range("A1:F1") = "" Then
Range("A6:F6") = ""
End If
End Sub

But this obviously is not the case.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I'm not understanding what you are trying to do here.
Code:
[COLOR=#333333]Range[/COLOR][COLOR=#ff0000]("A6:F6")[/COLOR][COLOR=#333333] = Me.Range[/COLOR][COLOR=#ff0000]("A6:F6")[/COLOR][COLOR=#333333].Value[/COLOR]
Please explain in simple English. The "Me." term usually refers to a form but you have not mentioned any form. Also with a form there is no range object. I am confused. Instead of providing some code that is not clear, perhaps a step by step explanation as if we were standing in line at a coffee shop.
 
Upvote 0
I do apologize for the improper English

If A1 is "NDO" then A6 should populate "NDO".

But

It should be possible for me to override the "NDO" in A6 with anything I wish to type there. ( Hence---> Me.Range("A6").Value)

If

I delete/remove the "data" I typed into A6 and A1 still "NDO" then A6 should populate to "NDO" again.

Now the tricky part was

If A1 has no value/empty/nothing

then A6 should also be empty/nothing

but

I must still be able to input/type my own data into A6 even if A1 is empty/nothing and the data should remain in A6 until I physically delete the data in A6

All of the above is working but the challenge I am facing is to get this to work from A1 up to Z1 and A6 up to Z6 (so basically A1 and A6 work together, B1 and B6 work together and C1 and C6 and so on.

hopefully this time round I am making sense.......
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

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