I have a spreadsheet of x amount of names, with the last name being in column A, and the first name in column B. I am trying to concatenate them to get the First(B) and Last(A) name in the same Column for the entire list of names. Was wondering if someone has or could write a macro for this so it will read in one column ("lastname", "firstname") x amount of times. Thanks!
Give this a try:
Sub NameGenerator()
Dim N As Long, DQ As String
N = Cells(Rows.Count, 1).End(xlUp).Row
DQ = Chr(34)
For i = 1 To N
Cells(i, 3) = "(" & DQ & Cells(i, 2) & ", " & Cells(i, 1) & DQ & ")"
Next i
End Sub
Related
I have some raw data below which I am trying to format in Excel Spreadsheet.
The Data is formated as below
I need to format this data in VBA to where it looks like this.
The last row, "CTP Parameters", needs to be separated into key value pairs while the other information stays the same until the part number changes. This some of the code that I have in VBA. I know I need to put this information into a dynamic array. I am new to VBA though.
Sub SplitKeyPairs()
'Variables
Dim myString As String
Dim kpArr() As String
Dim i, j As Integer
i = 2
j = 2
Do
myString = Range("F" & i)
'Split the string based on the line break
For Each keypair In Split(myString, "~")
'Split the keypair value
kpArr = Split(keypair, "^")
'Copy keys on B column and values on C column
Range("G" & j) = kpArr(0)
Range("H" & j) = Replace(kpArr(1), "~", "")
j = j + 1
Next
i = i + 1
Loop While Range("F" & i) <> ""
End Sub
Hi I'm trying to create a loop that identifies a specific string in column "B", and SUMs up the values in column "D" of the same row. So far I've been able to identify the "cash" but now I don't know how to describe column "D" of the SAME row and sum it up. Please help!
Below is what I've got so far for this loop.
Dim CD As Long
Dim text As String
Dim Z As Long
CD = 0
For Z = 1 To Range("B" & Rows.Count).End(xlUp).Row
text = Range("B" & Z).Value
If Left(text, 4) = "Cash" Then
Sum....
You could certainly do something like:
For Z = 1 To Range("B" & Rows.Count).End(xlUp).Row
text = cells(Z,2).Value
If Left(text, 4) = "Cash" Then
Sum.... Zum = Zum + cells(Z,4).value
However, the computation could be done with a simple worksheet formula
=SUMIF(B:B,"cash*",D:D)
Following the code you have provided, this would be what you are looking for:
Sub calculateSum()
Dim CD As Long
Dim text As String
Dim Z As Long
'Create a variable to store the sum and set its value to 0.
Dim sum As Double
sum = 0
CD = 0
For Z = 1 To Range("B" & Rows.Count).End(xlUp).Row
text = Range("B" & Z).Value
If Left(text, 4) = "Cash" Then
'Increase the sum by the value stored in column D on the same row.
sum = sum + Range("D" & Z).Value
End If
Next Z
'Display the final result (sum).
MsgBox "Sum: " & sum
End Sub
I have an excel document that is, and looks physically like a report. I only need some of the data. What is the best of coming up with a formula that gets me this information. Document has 88 entries.
You can click the image for a full-size version:
I want to come up with a search that returns the stuff in yellow. Any idea how to get that done? Or is this a manual search type of deal? I'm asking, not because I want to save 3 hours on doing this, but because I would like to save time in the future. Thanks!
As long as your template is in the same format, the below code should work. I tried to keep it as simple as possible so you can see what the individual steps do. You an adjust the columns where the data is pasted to suit. You will need to first create a sheet called 'Extract' and change any occurrence of 'YourSheetNameHere' within the code.
Sub Extract()
Dim Page, Company, Num, Name, ProjMan, TotalVal, Fee As String
Dim r, c As Integer
c = 1
Sheets("YourSheetNameHere").Select
For r = 1 To 4680
If Left(Range("J" & r).Value, 4) = "Page" Then
'Stores the values
Page = Range("J" & r)
ProjMan = Range("J" & r + 2)
TotalVal = Range("J" & r + 4)
Company = Range("J" & r + 4)
Num = Range("J" & r + 6)
Name = Range("J" & r + 7)
Fee = Range("H" & r + 31)
'Pastes the values in a new sheet called Extract (which you will need to create first)
Sheets("Extract").Select
Range("A" & c) = Page
Range("B" & c) = ProjMan
Range("C" & c) = TotalVal
Range("D" & c) = Company
Range("E" & c) = Num
Range("F" & c) = Name
Range("G" & c) = Fee
c = c + 1
Sheets("YourSheetNameHere").Select 'You will need to adjust to suit
End If
Next r
End Sub
Is there any way in Excel to 'paste' a formula over a column so that each cell receiving the formula is taken as input in the formula? For example, I would like to write =Text() over a range without first putting Text(A1) over an empty column, dragging it down, and pasting the results into the original column. Is this possible? Thanks!
Here is an example that replaces a column of values with a column of formulas:
Sub Formulate()
Dim N As Long, i As Long, dq As String
N = Cells(Rows.Count, "A").End(xlUp).Row
dq = Chr(34)
For i = 1 To N
v = Cells(i, 1).Value
Cells(i, 1).Formula = "=Text(" & v & "," & dq & "mm/dd/yyyy" & dq & ")"
Next i
End Sub
In Column B I have partial links such as B003KIU14O
What I'm trying to achieve is to have it converted to hyperlink and stayed in the same Column B.
My static (first part of link) link is http://www.amazon.com/gp/product/
The complete link looks like this: http://www.amazon.com/gp/product/B003KIU14O
If possible I would love to have the Visual value in Column B to display B003KIU14O and have hyperlink
light the cells you wish to convert and run this tiny macro:
Sub dural()
Dim r As Range, s As String, DQ As String
DQ = Chr(34)
s = "http://www.amazon.com/gp/product/"
For Each r In Selection
v = r.Value
r.Formula = "=HYPERLINK(" & DQ & s & v & DQ & "," & DQ & v & DQ & ")"
Next r
End Sub
EDIT#1:
To avoid manual selection:
Sub dural()
Dim r As Range, s As String, DQ As String
DQ = Chr(34)
Dim rBig As Range
s = "http://www.amazon.com/gp/product/"
Dim N As Long
N = Cells(Rows.Count, "B").End(xlUp).Row
Set rBig = Range("B1:B" & N)
For Each r In rBig
v = r.Value
r.Formula = "=HYPERLINK(" & DQ & s & v & DQ & "," & DQ & v & DQ & ")"
Next r
End Sub
I don't think you need Visual Basic, if you don't mind the hyperlink appearing in an adjacent cell: Put the following in the cell where you want the hyperlink to appear (assuming your link appears in cell B1):
=HYPERLINK("http://www.amazon.com/gp/product/" & B1, B1)
Then copy down as necessary for other values in column B.
If you want the full hyperlink to appear, just drop the second parameter:
=HYPERLINK("http://www.amazon.com/gp/product/" & B1)