Few Commands With Meaning
Few Commands With Meaning
Next msgbox will show contents of cell A1, A2, A3 next causes increment of i
branchcount = j
Cells(i, "N").Value = Cells(i, "J").Value & " " & Cells(i, "K").Value join two
columns
Range("A1").CopyRange("C1")COPYCOMMANDcopiescontentsofcellA1intocellC1
Range("A1:A3").CopyRange("D1:D3")copiescontentsofcellsA1,A2,A3intocellDA1,D2,D3
Range("A1:A3").CopyRange("D1")
Cells(i, k + 1).Activate increment variable in cell increment cell value to next cell using variable
Range(Cells(j, "G"), Cells(j, "H")).Copy use "H" for fixed column or "1" for fixed row
Cells(i, LC)) has use cell with two variables defined as long Dim N As Long, i As Long, j As Long, LC As Long
IsEmpty(Cells(i, "A")) = False to check cell in col A and Row i is blank or not
N = Cells(Rows.Count, "A").End(xlUp).Row
N = Cells(1, Columns.Count).End(xlToLeft).Column
TO SELECT FILLED CELLS IN A ROW ADD COLOUR TO CELL OR RANGE OR to select two cells to select range
' MARKS filled cells in the row i from I1 to LC. AND ADD COLOUR TO THEM WITH INDEX 15
Sub test()
k = Cells(Rows.count, "A").End(xlUp).Row
MsgBox (k)
End Sub
MESSAGEBOX GIVES RESULT value of k here it counts number of filled rows in column A
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
How would I select a cell based on a variable beginPosition containing the row number. For example if my beginPosition
variable is 10, how would I select cell A10?
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Cells(1, var).Select
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
For var = 2 To N
MsgBox var
Cells(1, var).Select
MsgBox "move to next" loop if cell with vaiable contains text TOTAL
Else
End If
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Cells(1, var).Select CELLS REFERRED IN ROW 1 IN ALL COLUMNS GIVEN BY VARIABLE var
If Cells(1, var).Value = "TOTAL" Then IF USED WITH VARIABLE var TOCHECK IF IT CONTAINS TOTAL
ActiveCell.Offset(1, 0).Select TO SELECT CELL BELOW USE OFFSET
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks for the help! Everything has solved itself when I used different approach in referring to workbooks. It looks strange but it
seems to work fine:
I figured that I didn't have to refer to a specific worksheet if I'm only interested in the default one and it works great now!
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
with sheets("Sheet1")
.Range(.Cells(2, 3), .Cells(10, 3)).Copy _
Destination:=ws2.Range(ws2.Cells(3,4))
end with
The prefixing period (aka . or full stop) means that the parent of .Range and .Cells is defined with the With...End With
statement. To shorten the code necessary to properly define the range on Sheet2, I assigned a worksheet type variable and
used it to show the parent of both the range and the cells.
MsgBox ThisWorkbook.Path & vbNewLine & ThisWorkbook.Name just above theWith Sheets("Data_Sheet") and verify if the
macro is running from the correct workbook?
Set FindRow = Range("A:A").Find(What:="ProjTemp", _' This is what you are searching for
After:=.Cells(.Cells.Count), _ ' This is saying after the last cell in the_
' column i.e. the first
LookIn:=xlValues, _ ' this says look in the values of the cell not the formula
LookAt:=xlWhole, _ ' This look s for EXACT ENTIRE MATCH
SearchOrder:=xlByRows, _ 'This look down the column row by row
'Larger Ranges with multiple columns can be set to
' look column by column then down
MatchCase:=False) ' this says that the search is not case sensitive
How to find row number of cell within a range : how to use text as variable : use content of cell as variable
As cell changes with cell i the value of variable (Collegename) changes with it
to find or search in another sheet assign the contents of the cell to a variable in sheet1 and select sheet2 before you find or
search
MsgBox Collegename
shb.Select
j = FindRow.Row
MsgBox j
how do you tell vba to go back up to an earlier line in your code GOTO any line
goto back go up goback use line1:
Sub gotoExample()
Dim a As Integer
a=1
line1:
a=a+1
If a < 10 Then
GoTo line1
End If
End Sub
Place a command button on your worksheet and add the following code lines:
For i = 1 To 6
For j = 1 To 2
Cells(i, j).Value = 100
Next j
Next i
If you want to select from A1 to the end of the used range, you can use the SpecialCells method like this
With ActiveSheet
.Range(.Cells(1, 1), .Cells.SpecialCells(xlCellTypeLastCell)).Select
End With
Place a command button on your worksheet and add the following code lines:
For i = 1 To 6
For j = 1 To 2
Cells(i, j).Value = 100
Next j
Next i
NESTED FOR LOOP FILL ALL ROWS FILL ALL COLUMNS USIMNG TWO VARIABLES
Sub addtext1()
Sheets("Sheet1").Select
R = Cells(Rows.Count, "A").End(xlUp).Row
' R counts number of filled rows worksheet.
C = Cells(1, Columns.Count).End(xlToLeft).Column
' Ccounts number of filled columns in row 1 worksheet
For i = 2 To R
For j = 2 To C - 3
Else
Cells(i, j).Value = "YES"
j=j+3
End If
Else
Cells(i, j).Value = "YES"
j=j+3
End If
Next j
Next i
End Sub
Very important to activate cell so that it move to next column ele it will use the
macro in samerow
R = Cells(Rows.Count, "E").End(xlUp).Row
' R counts number of filled rows worksheet.
MsgBox R
R = R + 200
MsgBox R
For i = 3 To R
Cells(i, "C").Activate
If Cells(i, "C").Value = "" Then
MsgBox i
Else
ActiveCell.EntireRow.Insert
i=i+1
End If
Next i
End Sub
' stop of Blank row based on FILLED E COLUMN. SHEET NAMED DATA GETS MODIFIED
' COLUMN B HAS ENGG COLLEGE NAMES WITH BLANKS SO MACRO TESTS BLANK IN COLUMN C
' insert new blank row based on COLUMN B
'1000 incremented in R so that all even if 200 rows are added with the macro even then the loop continues till end
Dim i As Long, j As Long, k As Long
Sheets("branchcount").Select
For i = 1 To 2000
k=i
MsgBox i
j=0
line1:
End If
MsgBox j
i=k
Next i
End Sub