Copy value into rows between two blank rows [closed] - vba

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Please see image below. What I would like to do is copy the value in cell C3 into column B into rows 4-13. Then copy vehicle number in cell C16 into B17 and so on.
Basically this displays all the trips a vehicle has made and the data for different vehicles is separated by blank rows.
Please help.
Check image below:

given your data structure you could try this:
Option Explicit
Sub main()
Dim vehicleRng As Range, cell As Range
With Range("A2", Cells(Rows.count, 1).End(xlUp))
.AutoFilter field:=1, Criteria1:="VEHICLE"
Set vehicleRng = .Resize(.Rows.count - 1).Offset(1).SpecialCells(xlCellTypeVisible)
End With
ActiveSheet.AutoFilterMode = False
For Each cell In vehicleRng
With cell
Range(cell.Offset(1), cell.End(xlDown).Offset(-1)).Offset(, 1).Value = cell.Offset(, 2)
End With
Next
End Sub

Related

I would like to have VB code in excel. If cell "A1:A200 is blank then concananet cells B1:C1 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I would like to have VB code in excel. If cell "A1:A200 is blank then concananet cells B1:C1.
enter image description here
Sub FillColumnA()
Dim i As Long
For i = 1 To 200
If Cells(i, 1).Value = "" Then
Cells(i, 1).Value = Cells(i, 2).Value & Cells(i, 3).Value
End If
Next
End Sub
no loops
Sub FillColumnA()
With Range("A1:A" & Cells(Rows.Count, 2).End(xlUp).Row)
.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=CONCATENATE(RC2,RC3)"
.Value = .Value
End With
End Sub
Shift your data down 1 row and add headers. Set your data up as a table by selecting a populated cell in the range and pressing Ctrl+T. Then in column D2 put
=IF(ISBLANK(A2),CONCATENATE(B2,C2),"")
The table will autofill the rest of the columns with the formula.
If you simply press Ctrl+T without shifting your data and then don't select my table has headers, the data will be shifted for you.

Excel counting rows that are not empty in Vlookup value [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to count the total number of cells that have values for the row that I'll be looking up using their name. I have a different sheet for looking up the value I tried COUNTA and VLOOKUP. Is there any way to combine these two so I'll end up with the correct result?
Please see screenshot.
Thank you!
Use INDEX(,MATCH()):
=COUNTA(INDEX('Sheet1'!C:X,MATCH("Jessel Rayes",'Sheet1'!A:A,0),0))
Here is a vba function that looks up the value you define (first input) in a specified range (second input) and then returns the number of empty cells in the same row right from this cell for a specified amount of columns (third input).
Function TLookupT(Value As Variant, arr As Range, column As Long)
x = 0
For Each Cell In arr
If Cell.Value = Value Then
For i = 1 To column - 1
If Cell.Offset(0, i) = "" Then
x = x + 1
End If
Next i
End If
Next Cell
TLookupT = x
End Function

Multiple results with VBA Vlookup [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have got two sheets, one with data like this:
For one person there can be couple of rows with answers.
And second sheet with this data:
Here one person had only one row with answers.
Based on the surnames from second table I want to search the person in first table and if the person is present copy the whole row to another sheet. So my final output table will looks like this:
My idea is that the algorithm should take the surname from table in Data 2 sheet on look for it in Data 1 sheet if is present then copy whole row into A3 Output sheet, next search the rest of Data 2 for another appearance. If blank cell then take another surname from Data 2 table and do it up to the point where in Data 2 table blank space is detected. But I have no idea how to translate it into VBA code.
Could anyone help with some clues? Or macro that I can use here?
I would be really thankful for any help.
Here's a VBA subroutine that I believe will do what you asked, not sure if it is what you want. This is assuming you already have a tab to receive the data to be copied; the tabs being used are MRWV1 = names to select, MRWV2 = Data sheet of rows to copy and MRWV3 = sheet to receive the copied data.
Sub MRWV()
'
' MRWV Macro
'
' Housekeeping
vFoundKt = 1
vSourceRows = 0
vDataRows = 0
' Select the sheet with the five rows with the names to select
Sheets("MRWV1").Select
vSourceRows = Cells(Rows.Count, 1).End(xlUp).Row
Sheets("MRWV2").Select
vDataRows = Cells(Rows.Count, 1).End(xlUp).Row
'Get names from source sheet
For iSource = 2 To vSourceRows
Sheets("MRWV1").Select
Range("A" & iSource).Select
vSourceName1 = ActiveCell.Value
Range("B" & iSource).Select
vSourceName2 = ActiveCell.Value
'Look through data sheet for matching names
For iData = 2 To vDataRows
Sheets("MRWV2").Select
Range("A" & iData).Select
vDataName1 = ActiveCell.Value
Range("B" & iData).Select
vDataName2 = ActiveCell.Value
If vSourceName1 = vDataName1 And vSourceName2 = vDataName2 Then
vFoundKt = vFoundKt + 1
Range("A" & iData & ":I" & iData).Select
Selection.Copy
Sheets("MRWV3").Select
Range("C" & vFoundKt).Select
Selection.PasteSpecial Paste:=xlPasteValues,Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Next
Next
End Sub

Copy paste in VBA depending on number in cells [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Is it possible to have a VBA code check columns B,E,H,K,N from sheet1 for a number greater than 0, then copy and paste that cell, the one before and the one after in sheet2 in columns A,B and C?
Here is the code I've been using but it's taking the whole Row and that's not exactly what I want as it gives a lot of content that's unnecessary:
Sub Epicerie()
For Each Cell In Sheets("Liste").Range("B:B, E:E, H:H, K:K, N:N")
If Cell.Value > 0 Then
matchRow = Cell.Row
Rows(matchRow & ":" & matchRow).Select
Selection.Copy
Sheets("Listepret").Select
ActiveSheet.Rows(matchRow).Select
ActiveSheet.Paste
Sheets("Liste").Select
End If
Next
End Sub
I think you are after something like the code below:
Option Explicit
Sub Epicerie()
Dim Cell As Range
For Each Cell In Sheets("Liste").Range("B:B, E:E, H:H, K:K, N:N")
If Cell.Value > 0 Then
With Sheets("Listepret")
' copy paste in 1 line to the next empty row at Column "A"
Cell.Offset(, -1).Resize(1, 3).Copy Destination:=.Range("A" & .Cells(.Rows.Count, "A").End(xlUp).Row + 1)
End With
End If
Next
End Sub

How to find the days difference between two dates [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have been working on finding the Days difference between the dates found in Column A and column B. The dates in both columns are not constant thus I would need a code that would allow to read both dates in column A and B and find the Days difference between those two dates until the last row is empty.
Is there any code that I could use to find the Days difference between column A and B with a range of more than 500 rows?
Instead of using vba just enter the formula for the first row on C1 :
=ROUND(a1,0)-ROUND(b1,0)
Then just the formula to the end of exisiting rows.
If you insist using vba code use the simple code below:
Dim LastRow As Long
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Range("c1").Select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-1],0)-ROUND(RC[-2],0)"
Range("c1").AutoFill Destination:=Range("C1:C" & LastRow)
End Sub