Assigning and declaring a alphanumeric value to a variable and referrring it through EXCEL VBA

Vinodhkumar

New Member
Joined
Jan 9, 2013
Messages
3
Hi All,

I am new to this forum. But I am happy that I have registered with this because I have learnt lot many things through this forum. You people rock!!!!! And thank you!!!!

Now I have one requirment, which is bothering me for the past 3 days. Hope you people can easily get me out of this.

How should we declare and assign a alphanumeric value to variable in Excel VBA and refer that through code? and also could you please tweak the code to finish the process I have mentioned under: Requirement.

Note:
Unique ID sheet : Holds all the Unique Ids of the values.
Sheet1: Holds 'alphanumeric' and also 'String values' in two separate columns
Sheet2: Holds 'Aplhanumeric' values in a column



My Code is like this:

sub copyIDs()

For i = 2 to 100

Id = worksheets("UniqueID").cells(i,2).value

if (worksheets("Sheet1").cells(i,2).value like Id) then
if (worksheets("Sheet2").cells(i,2).value like Id) then
worksheets("Sheet2").cells(i,3).value = worksheets("Sheet1").cells(i,2).value
end if
next
end sub

REQUIREMENT

What it should do is, from the 'Unique ID' sheet it should take the first value, check it with 'Sheet1' and 'Sheet2' value, if the ID is present then it should copy the 'Name' from Sheet1 corresponding to the alphanumeric value and should paste in sheet2 adjacent to the alphanumeric value present there.


I need your help in finishing this task. One of the challenges i faced is that 'I am not able to assign the alphanumeric value to the variable 'ID'. It always return me a blank.'
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Sorry if im not clear some where. I need to finish this before tomorrow 8:00 PM (IST). So in a hurry to get this posted here and try some help from you people.
 
Upvote 0
Can you please supply an example of what would be on each sheet and the outcome: example:

Unique ID Sheet: ABCD1234
Sheet1: ABCD1234 with "Test" as String
Sheet2: ABCD1234

unique ID is on all sheets, copy test and paste next to ABCD1234 on sheet2, something like that?
 
Upvote 0
Hi Torres, you right.
UniqueIDs will be same like you have mentioned but with just two aplbhabets and 5 digits. (like AB12345)
and Sheet1 will have this Unique ID there and also a text value in the adjacent cell. (like: D1: AB12345 and E1:Text)
and Sheet2 will have the unique ID alone. So have to copy the 'Text' into the adjacent column of AB12345 in Sheet2
 
Upvote 0
See if this will do the trick, change the columns to fit your sheets.

Code:
Sub UniqueIDLookup()

Set a = Sheets("Unique ID")
Set b = Sheets("Sheet1")
Set c = Sheets("Sheet2")
Dim i As Long
Dim findValue As Variant
Dim return1, return2 As Range

For i = 1 To a.Range("B" & Rows.Count).End(xlUp).Row
findValue = a.Range("B" & i)
Set return1 = b.Range("D:D").Find(What:=findValue, LookIn:=xlFormulas, LookAt:=xlWhole)
Set return2 = c.Range("D:D").Find(What:=findValue, LookIn:=xlFormulas, LookAt:=xlWhole)

If return1 Is Nothing Or return2 Is Nothing Then
    i = i
    Else
    return2.Offset(0, 1) = return1.Offset(0, 1)
End If

Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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