Loop - take value from two cells

rohmadi02

New Member
Joined
Nov 3, 2011
Messages
3
Hello..
I am new to VBA excel ..
I have a piece of VBA to be run on SAP application.
this code is running and should take value from cell in A & B but this is running only take value in cell A. it's does not touch cell B at all.
Also when there is NO further value / empty , the loop should be stop.

could you please advice what the syntax should be in this case?
Thank you .

Dim vNilai As Variant

With SAPSesi

.findById("wnd[0]").maximize
.findById("wnd[0]/tbar[0]/okcd").Text = "/NMM02"
.findById("wnd[0]").sendVKey 0

For Each vNilai In Workbooks("LoopTrial.xls").Worksheets("Sheet1").Range("A2:A20,B2:B20")

.findById("wnd[0]/usr/ctxtRMMG1-MATNR").Text = vNilai
.findById("wnd[0]/usr/ctxtRMMG1-MATNR").caretPosition = 8
.findById("wnd[0]").sendVKey 0
.findById("wnd[0]").sendVKey 0

'ActiveCell.Offset(0, 1).Select

.findById("wnd[0]/usr/tabsTABSPR1/tabpSP13/ssubTABFRA1:SAPLMGMM:2000/subSUB4:SAPLMGD1:2486/txtMARC-EISBE").Text = vNilai
.findById("wnd[0]/usr/tabsTABSPR1/tabpSP13/ssubTABFRA1:SAPLMGMM:2000/subSUB4:SAPLMGD1:2486/txtMARC-EISBE").SetFocus
.findById("wnd[0]/usr/tabsTABSPR1/tabpSP13/ssubTABFRA1:SAPLMGMM:2000/subSUB4:SAPLMGD1:2486/txtMARC-EISBE").caretPosition = 2
.findById("wnd[0]").sendVKey 0
.findById("wnd[0]/tbar[0]/btn[11]").press

Next vNilai

.findById("wnd[0]/tbar[0]/okcd").Text = "/n"
.findById("wnd[0]").sendVKey 0


End With

below is the value in cell A&B

-- removed inline image ---

<table border="0" cellpadding="0" cellspacing="0" width="310"><colgroup><col style="width:48pt" width="64"> <col style="mso-width-source:userset;mso-width-alt:5046;width:104pt" width="138"> <col style="mso-width-source:userset;mso-width-alt:3949;width:81pt" width="108"> </colgroup><tbody><tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt;width:48pt" height="17" width="64">
</td> <td class="xl24" style="width:104pt" width="138">A</td> <td class="xl25" style="width:81pt" width="108">B</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">1</td> <td class="xl24">MATNR</td> <td class="xl25">EISBE</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">2</td> <td class="xl24">96041313</td> <td class="xl25">26</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">3</td> <td class="xl24">96487181</td> <td class="xl25">51</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">4</td> <td class="xl24">2421241</td> <td class="xl25">25</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">5</td> <td class="xl24">2408447</td> <td class="xl25">30</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">6</td> <td class="xl24">2421025</td> <td class="xl25">15</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">7</td> <td class="xl24">3067001</td> <td class="xl25">10</td> </tr> <tr style="height:12.75pt" height="17"> <td class="xl24" style="height:12.75pt" height="17">8</td> <td class="xl24">2419745</td> <td class="xl25">5</td> </tr> </tbody></table>


-- removed inline image ---
Brgds,
Rohmadi
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Watch MrExcel Video

Forum statistics

Threads
1,123,530
Messages
5,602,196
Members
414,513
Latest member
junbuggle

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
Top