Horizontal Loop

0 votes

I'm trying to write a macro that does the following:

  1. Loop through each row in the table1 starting with 1 to 50
  2. Loop through each column of the respective row starting with 2 to 100
  3. Concatenate for each row in column 1 all the single fields in columns 2 to 100 with a "|" in-between.

See my code below. I get an error for.Range.Cells(lRow, 1) = .Range.Cells(lRow, 1) & "|" & .Range.Cells(lRow, lCol)

Option Explicit

Sub horizontal_loop()

Dim lRow, lCol As Long

With Worksheets("table1")

    For lRow = 1 To 50
    
       For lCol = 2 To 100
    
            .Range.Cells(lRow, 1) = .Range.Cells(lRow, 1) & "|" & .Range.Cells(lRow, lCol)

       Next lCol
    
    Next lRow
    
End With
    
End Sub
Jan 15, 2023 in Others by Kithuzzz
• 38,000 points
486 views

1 answer to this question.

0 votes

There is no need to use Range if you are using Cells.

.Cells(lRow, 1) = .Cells(lRow, 1) & "|" & .Cells(lRow, lCol)

I hope this helps you.

answered Jan 15, 2023 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

How to use for loop in Flutter?

Hi@akhtar, As the name suggests Dart for in ...READ MORE

answered Sep 3, 2020 in Others by MD
• 95,460 points
19,168 views
0 votes
0 answers

MS Excel - SumProduct formula with Loop

1 I have 4 arrays of data where ...READ MORE

Feb 18, 2022 in Others by Edureka
• 13,690 points
420 views
0 votes
1 answer

Loop formula in excel vba

You can use an IF statement to ...READ MORE

answered Nov 25, 2022 in Others by narikkadan
• 63,600 points
841 views
0 votes
0 answers

Excel VBA: Open Hyperlinks in a loop and copy paste download link in a sheet

I want to click on a number ...READ MORE

Dec 25, 2022 in Others by Kithuzzz
• 38,000 points
1,379 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,212 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,664 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
908 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
1,053 views
0 votes
1 answer

Writing SEO friendly url gets infinite loop asp.net

you should know that regex avoid cases ...READ MORE

answered Feb 11, 2022 in Others by narikkadan
• 63,600 points
803 views
0 votes
1 answer

XLOOKUP Formula Issue Horizontal & vertical lookup

Actually, your ranges are wrong. To correct ...READ MORE

answered Nov 5, 2022 in Others by narikkadan
• 63,600 points
591 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP