I want to go to the next column each time I click on a button. I have tried this but it does not work:
Dim i As Integer
If i = 0 Then
i = 4
End If
i = i + 1
ffc = ActiveCell.Offset(x, i).Column
I used ffc because I want to add it to other button to insert the value "A" or "P" like this:
Sheet3.Cells(x, ffc).Value = "A"
To understand more, my project is for record attendance by days. My problem is just moving to the next column.
I have tried this too
ffc = ActiveCell.Offset(1, 0).Row
It works but it's working with rows, which mean when I go down in rows the column move one step and I want the column move when I only press the button
Please try the code below
Dim i As Integer
For i = 1 To Columns.Count
ActiveSheet.Cells(1, i).Select
Next
Related
I want to copy all rows that have a specific value in column E and then insert them (NOT PASTE! so i want to insert new rows start at cell A29) on another sheet.
The sheet I want to copy from is called "owssvr" and the one I want to copy to is called "AOB Approval Form". I want to insert the copied rows starting Cell A29 in the "AOB Approval Form".
When i run the code, nothing happens. No error message pops up.
Few definition of my code below:
LastRow: The last row of the "owssvr" sheet
PrimaryAOB: value that i want to lookup for in column 5. It is on the "AOB Approval Form" sheet
Here is my code:
For k = 2 To lastRow
If Worksheets("owssvr").Range("E" & k).Value = primaryAOB Then
Worksheets("owssvr").Rows(k).Copy
Worksheets("AOB Approval Form").Rows(k + 27).Insert Shift:=xlDown
Application.CutCopyMode = False
End If
Next k
THANK YOU!
I copied your code into a new module in a blank workbook, then made the necessary mods to make it run (which it did). It looks the same as yours:
Sub Question()
Dim k As long, lastRow As Long
Dim primaryAOB As String
lastRow = Sheets(1).Range("E" & (ActiveSheet.Rows.Count)).End(xlUp).Row
primaryAOB = Sheets(2).Range("A1").Text
For k = 2 To lastRow
If Worksheets("owssvr").Range("E" & k).Value = primaryAOB Then
Worksheets("owssvr").Rows(k).Copy
Worksheets("AOB Approval Form").Rows(k + 27).Insert Shift:=xlDown
Application.CutCopyMode = False
End If
Next k
End Sub
Since this worked, you may have just had some little syntax error somewhere while defining the variables. show us more of your procedure, that may reveal the issue! Also, have you run your code line by line? (F8)
I'm just getting all the text with red font-color on a first sheet and then stored it in an array. I then want to navigate to another sheet and activate a specific cell where I want to initially put the values inside my previous array. But the part where I activate a cell on the other sheet resulted to Error 400. I'm confident enough that it's right since I already used it before. I don't know if I have some manipulation at the first part of my code that affects that.
Sub isFontRed()
Cells(2, 1).Select
Dim missingJobs(0 To 600) As String
Dim size As Integer, row As Integer, col As Integer, jobIndex As Integer
jobIndex = 0
For row = 2 To 10 '600
For col = 1 To 2
If (CStr(Cells(row, col).Font.ColorIndex) = 3) Then
missingJobs(jobIndex) = Cells(row, col)
jobIndex = jobIndex + 1
End If
Next col
Next row
Dim jobs As String
jobs = ""
For i = 0 To UBound(missingJobs) - 1
jobs = jobs + missingJobs(i) + ", "
Next i
Worksheets("New Jobs in New Folder").Activate
Cells(4, 2).Activate
End Sub
It's been a while but are you trying to select cells(4, 2)? I don't think you can 'activate' a cell like you can a worksheet. Try Cells(4, 2).Select instead.
http://imgur.com/zEm7hT7
In my image I have my form which upon entering information into the text boxes and pressing enter will place the information into the correct places below the titles, what i'm wanting to do is either have a next button that will go down one row and a back button that will go up one row and allows me to enter information into a 'database' per say or i would like to have it automatically jump down one row upon clicking 'Enter'. I have looked and I can't find anything that is quite what i'm asking and response is great, thanks.
This is what i have so far.
Private Sub CommandButton1_Click()
Dim x As Integer
x = Cells(1, 1).End(xlDown).Row + 1
Cells(x, 1) = TextBox1.Value
Cells(x, 2) = TextBox2.Value
Cells(x, 3) = TextBox3.Value
Cells(x, 4) = TextBox4.Value
Cells(x, 5) = TextBox5.Value
End Sub
Replace x=2 with finding the next empty row
If Cells(2,1) = "" Then
x = 2
Else
x = Cells(1,1).End(xlDown).Row + 1
End If
I am using a VBA code to insert rows below based on a specific text and its occurrence .
I am using the following code to do so
Sub try()
Dim c As Range
For Each c In Range("A1:A100")
If c.Value Like "*COLLECTION*" Then
c.Offset(1, 0).EntireRow.Insert
End If
Next c
End Sub
I want to have the text BALANCE below the COLLECTION cell instead of blank row.
I want to insert the BALANCE row below the last COLLECTION entry, for example if there are two collections rows serially then I want to add the BALANCE row after the 2nd collection row. but with the above VBA code I am getting blank rows below to the each collection row.
My Collection and balance rows are in the column A
Before macro Image kindly check
After macro I want like this Image kindly check
I would do this using a loop from row 1 till last filled row in column A. Then having a boolean marker which is true while the cell value in current cell is like "*COLLECTION*" but false while not. So if the current cell is not like "*COLLECTION*" but the marker is true then the last cell above the current cell was like "*COLLECTION*". Then insert a new row with "BALANCE" if that cell is not already "BALANCE".
Sub try()
Dim c As Range
Dim lRow As Long
lRow = 1
Dim lRowLast As Long
Dim bFound As Boolean
With ActiveSheet
lRowLast = .Cells(.Rows.Count, 1).End(xlUp).Row
Do
Set c = .Range("A" & lRow)
If c.Value Like "*COLLECTION*" Then
bFound = True
ElseIf bFound Then
bFound = False
If c.Value <> "BALANCE" Then
c.EntireRow.Insert
lRowLast = lRowLast + 1
c.Offset(-1, 0).Value = "BALANCE"
c.Offset(-1, 0).Font.Color = RGB(0, 0, 0)
End If
End If
lRow = lRow + 1
Loop While lRow <= lRowLast + 1
End With
End Sub
That's typically the kind of cases you want to start from the last cell, because inserting a row will mess up all counters from what is below.
In other words, the elegant for each is not really a good idea. Too unpredictable. An ugly, old simple For Step -1 is the way to go. Something like :
Sub Macro1()
For l = 100 To 1 Step -1
If Trim(Cells(l, 1)) = "COLLECTION" And Trim(Cells(l + 1, 1)) = "DEMAND" Then
Rows(CStr(l + 1) & ":" & CStr(l + 1)).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Cells(l + 1, 1) = "BALANCE"
End If
Next l
End Sub
Just tried on EXCEL 2013, seems to work as you want. There may be more elegant solutions, though.
EDIT : the idea is the following one :
_Begin by the last line(in fact, the last line cannot work, so one optimization could be to start from the prevo=ious one), and go to the first one
_If the line testes is "COLLECTION", and the next one is "DEMAND", then you need to insert a "BALANCE" line in between. It's done in 2 times, first insert an empty line, then add "BALANCE" in the newly created line.
I recently had a question regarding how to copy a cell value into all cells below it and stop based on when column A got to a blank cell. post
The excel sheet I'm working in has many divider rows that are color filled across the entire row to separate categories as you scroll down the sheet. I would like to be able to skip these separating rows in column A when the macro checks for a blank cell in column A. Or I would like to just assign StopRow to the first cell which has no formatting/no color/no value.
Here is what I have, thanks to Ripster earlier today, but I've failed incorporating a proper if then statement with what he came up with.
Sub Example()
Dim MasterValue As String
Dim StopRow As Long
Dim i As Long
'Get the master value
MasterValue = Range("C5").Value
'Get the first blank cell in column A
StopRow = Range("A1").End(xlDown).Row
'Start at row 6 and continue to the "Stop Row"
For i = 6 To StopRow
'Set every cell from row 6 in column 3 to the "Master Value"
Cells(i, 3).Value = MasterValue
Next
End Sub
Please help.
Thanks
This took me a while but I found solution to your problem ;)
If macro goes to cell with different color - checking and do nothin, next "i" is taken. This should do what u want. It's possible to add more color ;)
Link to colors - http://dmcritchie.mvps.org/excel/colors.htm
Sub Example()
For i = 6 To 1200
If Cells(i, 3).Interior.ColorIndex = 1 Then 'here is color black
Else
If IsEmpty(Cells(i, 1)) = True Then 'if cells in column "A" is empty then stop
Exit For
Else
Cells(i, 3).Value = Range("C5").Value
End If
End If
Next i
End Sub
Your conditions for StopRow aren't clear. Do you want to set StopRow when the cell has a conditional formatting rule or simply when it has a different format than the default ? A cell may have a rule but it may not be applied. Anyway, the function presented here is something you might find of use.
Copy the ActiveCondition function somewhere in a module and then change your for loop like so:
For i = 6 To StopRow
If ActiveCondition(Cells(i,3))=0 Then StopRow=i : Exit For
Cells(i, 3).Value = MasterValue
Next
If you want to check for change in font color that didn't come from conditional formatting then you'd need an extra line:
For i = 6 To StopRow
If ActiveCondition(Cells(i,3))=0 Then StopRow=i : Exit For
If Cells(1,3).Font.ColorIndex=0 Then StopRow=i : Exit For
Cells(i, 3).Value = MasterValue
Next
There are more elegant ways to do this but this solution is the easiest to implement in your code.
Hope this helps.