Vba loop through 2 columns

Flowcentric

New Member
Joined
Jul 29, 2016
Messages
14
Hi

I am creating a xml file from excel using vba. I have a list of stockcodes in a column and list of Warehouses in a column .
Each stock code must be attached to all warehouse. I want the code to selected the first stock code in column A and create the xml stockcode warehouse combination then move to A2 and then repeat then repeat the process until cell in the stockcode column = "" (so one stockcode many warehouses) Many thanks for your assistance

Here is the code below. I am not sure how to loop correctly
PHP:
Private Sub WarehouseWHXM()
Dim Row1
Dim STOCK
Dim Wh
Dim ROW


Document = Document & "<setupinvwarehouse>"


Row1 = 7
ROW = 2


 
Do While Range("AH" & ROW).Text <> ""
Do While Range("A" & Row1).Text <> ""


Document = Document & "<item>"
Document = Document & "<key>"
Document = Document & "<stockcode>" & Range("A" & Row1).Text & "</stockcode>"
Document = Document & "<warehouse>" & Range("AH" & ROW).Text & "</warehouse>"
Document = Document & "</key>"
Document = Document & "<costmultiplier>1.10</costmultiplier>"
Document = Document & "<unitcost>10.00</unitcost>"
Document = Document & "</item>"
Row1 = Row1 + 1
Loop
ROW = ROW + 1
Loop
Document = Document & "</setupinvwarehouse>"


'Create file
'
   Dim FSO
   Dim FSOFile
   Set FSO = CreateObject("Scripting.FileSystemObject")
   'Set FSOFile = FSO.CreateTextFile("\\Tevdbn-app-01\SYSPRO7\DFM\GlUpdate\GLChanges.xml")
   Set FSOFile = FSO.CreateTextFile("C:\New folder\new.xml")
   
    
  FSOFile.WriteLine (Document)
  FSOFile.Close


 'Housekeeping
 


Set FSO = Nothing
Set FSOFile = Nothing
Document = ""

End Sub
 
Last edited by a moderator:
Here try this, let me know if I got it a bit closer... Think I understand what your looking for...

PHP:
Private Sub WarehouseWHXM()

Dim rStock As Long, rWare As Long
Dim FSO As Object, FSOFile

Document = Document & "<setupinvwarehouse>"

rStock = 7
rWare = 2

Do While Range("A" & rStock).Text <> ""

   Do While Range("AH" & rWare).Text <> ""
        
        Document = Document & "<item>"
        Document = Document & "<key>"
        Document = Document & "<stockcode>" & Range("A" & rStock).Text & "</stockcode>" 
        Document = Document & "<warehouse>" & Range("AH" & rWare).Text & "</warehouse>" 
        Document = Document & "</key>" 
        Document = Document & "<costmultiplier>1.10</costmultiplier>" 
        Document = Document & "<unitcost>10.00</unitcost>" 
        Document = Document & "</item>" 
        rWare = rWare + 1 
       Loop

    rWare = 2
    rStock = rStock + 1

Loop 

Document = Document & "</setupinvwarehouse>"

'Create file
Set FSO = CreateObject("Scripting.FileSystemObject")
'Set FSOFile = FSO.CreateTextFile("\\Tevdbn-app-01\SYSPRO7\DFM\GlUpdate\GLChanges.xml")
Set FSOFile = FSO.CreateTextFile("C:\New folder\new.xml")

FSOFile.WriteLine (Document)
FSOFile.Close

'Housekeeping
Set FSO = Nothing
Set FSOFile = Nothing
Document = ""

End Sub
</div>
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
My pleasure :) Have a wonderful rest of your day... :biggrin:
 
Upvote 0
My pleasure :smile: Have a wonderful rest of your day... :biggrin:
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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