Need help structuring a IF/ELSE statement or using Select Case

adibakale

Board Regular
Joined
Apr 10, 2015
Messages
52
I am writing this macro to take a list of account numbers in column A of an excel sheet, enter those accounts in a terminal program called attachmate, and retrieve a SSN#, EIN# or a Central Bill #. I have been able to get it working until the point where I had to write multiple if/else statements to determine which type of # to retrieve.

The conditions are based on checking the Visa Type of the account after each account number is entered into attachmate.

In attachmate:

If Visa Type is not the letter "B" or Null, then get the SSN # which is located on the same page
If Visa type is null, then check if there is a visatype MCB
If Visa type MC-B is in the specified location, then get the Central Bill # which is located on the same page
if Visa type is "B" then send keystrokes F4,F5,F5 to go to page with EIN#
if EIN# is "000000000" then send keystroke F9 to go back to page with Central Bill # and get Central Bill#

This is the logic behind how I need to determine which number to get. I am new to learning VBA and learning fast, but I need help with writing this correctly, structuring it correctly and declaring variables correctly. I also tried to use a Select Case method but had difficulty with that as well. This is a little more complex than what I have written so far because it is working in Attachmate and is running in a For Next loop.

I only included the section I need help with

Any help would be greatly appreciated

Code:

For p = 1 To 10000 Step 59
For r = p + 7 To p + 58 Step 4




pull = Cells(r, 1).Value ' declare as variable?

Sess0.screen.WaitHostQuiet (g_HostSettleTime) ' Waits for attachmate before moving to next acct#
Sess0.screen.PutString pull, 1, 7 ' enters acct# into line 1 column 7 in attachmate
Sess0.screen.SendKeys ("0091 <Enter>") ' enter keystrokes in attachmate
Sess0.screen.WaitHostQuiet (g_HostSettleTime) ' need to wait for attachmate after using sendkeys



If InStr(Sess0.screen.GetString(3, 36, 1), "B") Then ' if the letter B is in this location get TIN#
Sess0.screen.SendKeys ("<Pf4> <Pf5> <Pf5> <Pf5>") ' enter keystrokes to get to page with TIN#
Sess0.screen.WaitHostQuiet (g_HostSettleTime) '
tnpull = Sess0.screen.GetString(20, 58, 10) 'declare as variable?
Cells(r, 2).Value = tnpull 'enters EIN# into excel from attachmate



ElseIf InStr(tnpull, "000000000") Then
Sess0.screen.SendKeys ("<Pf9>")
Sess0.screen.WaitHostQuiet (g_HostSettleTime)
cbpull = Sess0.screen.GetString(20, 58, 10)




Else
snpull = Sess0.screen.GetString(12, 6, 11) ' declare as variable?
Cells(r, 2).Value = snpull 'enters SSN# into excel from attachmate

End If
Sess0.screen.SendKeys ("<clear>") ' clear page and repeat

Next
Next
End Sub

 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,223,275
Messages
6,171,119
Members
452,381
Latest member
Nova88

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