ни в коем случае не является ответом, но больше подходит для того, чтобы помочь вам научиться чему-либокакой-то плохойВсе зависит от вашего уровня квалификации и уровня комфорта при работе с кодом.
Я только собираюсь обрисовать в общих чертах 2 метода
метод # 1 - Цикл по самим строкам / столбцам.Мне не нравится этот метод, поскольку его плохая практика - взаимодействие с объектами приложений является убийцей производительности.
dim rng as range, rcell as range
' you have to tell the compiler where stuff is at
' this is important and a commmon mistake that causes quesitons her eon SO
set rng = Thisworkbook.worksheets("Yoursheetname").Range("yourrange")
for each rcell in rng.Cells
'rcell is the current cell in the range you're looping through.
'Will physically loop through cells top to bottom, left to right
' do some processing.
next rcell
метод # 2 - Работа в памяти с массивами.Это предпочтительный метод и тот, который вы должны освоить, если вы планируете чаще использовать Excel-vba в будущем.
dim arr as variant ' you need this for dumping sheet to arrays
dim i as long, j as long
arr = THisworkbook.Worksheets("yoursheet").UsedRange
' there are many ways to get the desired range of a sheet - pick your favorite (after researching), and use that.
' the ubound and lbound functions literally mean upper and lower. It basically says for i equal beginning of array dimension to last.
' the number dictates what dimension of the array you want to loop through. Excel ranges are mutlidimensional by default. 1 = rows, 2 = columns
for i = LBound(arr,1) to UBound(arr,1)
for j = LBound(arr,2) to UBound(arr,2)
' do some processing
' array values can be accessed through this methods
' arr(i,j)
' arr(i, x) x being a number, like if you know i want column 7 of current iteration/row
' arr(i+1, j-1) plus values move down, or to the right (depending on dimension) while negative value go up or left (depending on dimension)
next j
next i
'to put stuff back on your sheet after processing
thisworkbook.worksheets("yoursheet").range("yoursheet").value = arr
это должно помочь вам разобраться в себе