Do Loop through a table with an If Statement in Excel VBA -Code Included
Grab the Free VBA Quick Reference Guide
https://chrisjterrell.com/p/getting-started
A subscriber to the youtube channel requested this video. The subscriber wanted to use a Do Loop to go through a table of data and if column 1 was the same as the row above column 2 would not change. If it was the same it would do nothing but if it was different then combine column 1 and 2 in column 2.
Code:
==========
Sub DowithIf()
rw = 11
cl = 2
erw = 1000
Do While rw _ erw
Cells(rw, cl + 1).HorizontalAlignment = xlCenter
If Cells(rw, cl) __ Cells(rw - 1, cl) Then
Cells(rw, cl + 1) = Cells(rw, cl) & " - " & Cells(rw, cl + 1)
Cells(rw, cl + 1).Interior.Color = 13431551
ElseIf Cells(rw, cl) = "" Then
Exit Do
End If
rw = rw + 1
Loop
Columns(2).Clear
Columns(3).AutoFit
End Sub
Видео Do Loop through a table with an If Statement in Excel VBA -Code Included канала EverydayVBA
https://chrisjterrell.com/p/getting-started
A subscriber to the youtube channel requested this video. The subscriber wanted to use a Do Loop to go through a table of data and if column 1 was the same as the row above column 2 would not change. If it was the same it would do nothing but if it was different then combine column 1 and 2 in column 2.
Code:
==========
Sub DowithIf()
rw = 11
cl = 2
erw = 1000
Do While rw _ erw
Cells(rw, cl + 1).HorizontalAlignment = xlCenter
If Cells(rw, cl) __ Cells(rw - 1, cl) Then
Cells(rw, cl + 1) = Cells(rw, cl) & " - " & Cells(rw, cl + 1)
Cells(rw, cl + 1).Interior.Color = 13431551
ElseIf Cells(rw, cl) = "" Then
Exit Do
End If
rw = rw + 1
Loop
Columns(2).Clear
Columns(3).AutoFit
End Sub
Видео Do Loop through a table with an If Statement in Excel VBA -Code Included канала EverydayVBA
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![Excel VBA Beginner Tutorial](https://i.ytimg.com/vi/G05TrN7nt6k/default.jpg)
![Excel VBA Introduction Part 15 - Do Until and Do While Loops](https://i.ytimg.com/vi/wGauctajWPQ/default.jpg)
![Use a For Loop and If Statement to loop through an Array and add data to another Sheet in VBA Code](https://i.ytimg.com/vi/hBqbKIDr37A/default.jpg)
![Excel VBA Basics #4 - IF THEN statements within the FOR NEXT loop](https://i.ytimg.com/vi/hS6yCdvyeA0/default.jpg)
![VBA - Looping through a Table (ListObject) and deleting a row](https://i.ytimg.com/vi/C77hCylKrIw/default.jpg)
![VBA to Copy and Paste Rows if Condition is Met - Excel VBA Example by ExcelDestination](https://i.ytimg.com/vi/qGZQIl9JJk4/default.jpg)
![EAF #37 - Excel VBA Loop to Find Records Matching Search Criteria](https://i.ytimg.com/vi/QOxhRSCfHaw/default.jpg)
![Excel VBA Basics #10 - Looping through a database and analyzing cells based on criteria](https://i.ytimg.com/vi/JEVh3hhEiRA/default.jpg)
![Excel VBA: Referring to Ranges & Writing to Cells (Range, Cells, Offset, Names)](https://i.ytimg.com/vi/acGJb9Oojho/default.jpg)
![Free Excel VBA Course #17 - Do While and Do Until Loop in Excel VBA](https://i.ytimg.com/vi/G1NbW4SWa7o/default.jpg)
![Excel Macro Class 3 - Looping through Ranges & Working with Cells](https://i.ytimg.com/vi/Ws9xskIadSk/default.jpg)
![Excel VBA IF THEN Statement (with ELSEIF & Looping in cells)](https://i.ytimg.com/vi/dUSQ7wZHM7A/default.jpg)
![Looping through the Cells in a Range in Excel VBA (Macro) - Code Included](https://i.ytimg.com/vi/cfzhUQj9s7c/default.jpg)
![Excel VBA basics: Data types, DIM & SET (Learn to use them correctly)](https://i.ytimg.com/vi/zfc9TYH3UvY/default.jpg)
![How to use MS Excel Tables via VBA](https://i.ytimg.com/vi/-Zvi3frxbis/default.jpg)
![Fully Automated Data Entry User Form in Excel - Step By Step Tutorial](https://i.ytimg.com/vi/P53T6oxgUVA/default.jpg)
![Run a Macro when a User Changes a Specific Cell, Range, or Any Cell in Excel](https://i.ytimg.com/vi/HsiwC9xg06c/default.jpg)
![5 Killer Excel VBA Tips Everyone Should Know](https://i.ytimg.com/vi/1UqfJ5DqGa4/default.jpg)
![Learn MS Excel - Video 403- VBA LOOP WITH FUNCTIONS- COUNTIF SUMIF](https://i.ytimg.com/vi/ziXCYxsZc-I/default.jpg)
![Excel VBA: Loop through cells inside the used range (For Each Collection Loop)](https://i.ytimg.com/vi/5bq3N99mNPE/default.jpg)