Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
HI I am new to using excel and only have a basic knowledge in designing macros. I want to be able to design a macro that can separate different invoice details depending on the company unique id into a separate sheet. only problem there is two or three rows that need to be moved together. How would I go about doing this?
For example:
Here is a sample picture of the data. what i want to do is copy the H and N in rows 1 and 2 deepening on the value in row D
Assuming your testing for something like 'is value > 25'
Sub Macro1()
Dim dat As Variant
Dim rng As Range
Dim i As Long
Dim cntr As Integer
cntr = 1
Set rng = [A1:A5]
dat = rng ' dat is now array (1 to 5, 1 to 1)
For i = LBound(dat, 1) To UBound(dat, 1)
If rng(i, 1).Offset(0, 3).Value > 25 Then
Sheets("Sheet2").Range("A" & cntr).Value = Range("A" & i).Value
cntr = cntr + 1
End If
Next
End Sub
Related
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 4 months ago.
Improve this question
Thats my data. I want to copy B2:M9 and insert it to P2. Furher, I want to copy B13:M20 and paste it to P2. Then I want to copy B24:M31 and paste it to P2 and so on.
Does anyone have an idea how I can do it?
Thank you!
Sub copypasta()
Dim nb_iter as Integer 'Number of ranges you have to copy
nb_iter = 3 'for example
Dim step as Integer
step = 0
for k = 1 to nb_iter
Range("B" & step + 2, "M" & step + 9).Copy
Range("P2").PasteSpecial , Paste:=xlPasteValues
step = step + 11 'you are adding 11 to both row numbers for each iteration
Next k
End Sub
My first attempt:
Sub Copypasta()
Dim i As Long
For i = 0 To 31
Range("B" & 2 + i, "M" & 9 + i).Copy
Range("P2").PasteSpecial Paste:=xlPasteValues
Next i
End Sub
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 2 years ago.
Improve this question
I'm new at coding but I've been asked to create some macro using VBA to speed up our working process in my company.
i have this code that performs a comparison macro:
Sub Compare_numbers()
Dim i As Long, LastRow As Long
Dim L, M, txt As String
LastRow = Cells(Rows.Count, "L").End(xlUp).Row
For i = 2 To LastRow
L = Cells(i, "L").Value
M = Cells(i, "M").Value
If L = M Then
txt = "they are equal"
ElseIf L > M Then
txt = "L is greater than M " & _
ChrW(&H2B61)
Else
txt = "L is less than M " & _
ChrW(&H2B63)
End If
Cells(i, "N") = txt
Next i
End Sub
this is the output of the code:
I need to add to this macro another piece of code that would replace all the arrow characters with a proper Shape from "Insert" tab (and also it should be responsive to the changing of cell's size) like the one in this sample picture:
Any idea to do this?
If you use a helper column N with the formula
=IFERROR((L:L-M:M)/ABS(L:L-M:M),0)
it will show
-1 if L < M
0 if L = M
1 if L > M
You can then easily use conditional formatting to show the arrows:
You can even hide the values if necessary so only the arrows are shown in N (just edit the rule accordingly).
I highly recommend not to use shapes for that as this will become very cumbersome, can easily fail and will put a heavy load on your sheet if the arrows have to change with the values automatically.
Also you would need to ensure that the shapes cannot be moved accidentally, because this would "destroy" the entire sheet.
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 7 years ago.
Improve this question
New to vba. Just starting to learn. I want to pull some specific data from a website.Code I am trying to modify is from Ron Retrieving specific data from website through excel.
Now this code work on a single url. I have urls in Column A of excel sheet and I want to macro to go one by one to all urls and paste results in Column B C D respectively.
Tried as best as my limited knowledge.
Regards
The main sub will get the ratings and the number of reviews for each URL in column A and will place them in Column B and C. I hope this help you a little.
Sub main()
Dim l As Long
l = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To l
test Range("A" & i)
Next
End Sub
Sub test(URL As Range)
my_url = URL.Value
Set html_doc = CreateObject("htmlfile")
Set xml_obj = CreateObject("MSXML2.XMLHTTP")
xml_obj.Open "GET", my_url, False
xml_obj.send
html_doc.body.innerhtml = xml_obj.responseText
Set xml_obj = Nothing
Set Results = html_doc.body.getElementsByTagName("i")
For Each itm In Results
If InStr(1, itm.outerhtml, "star-img", vbTextCompare) > 0 Then
numb_stars = itm.getAttribute("title")
Exit For
Else
End If
Next
Set Results = html_doc.body.getElementsByTagName("span")
For Each itm In Results
If InStr(1, itm.outerhtml, "reviewCount", vbTextCompare) > 0 Then
numb_rev = itm.innertext
Exit For
Else
End If
Next
URL.Offset(0, 1) = numb_stars
URL.Offset(0, 2) = numb_rev
End Sub
Preview of my output:
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I have the table below. Basically column A is the master data.
Column B, C and D will contain the some data in column A. Column B, C and D can have common data.
I want to compare data column A to column B,C and D.
In column Result, display all unmatch data.
Give this a try:
Sub MissingItems()
Dim N As Long, I As Long, J As Long, V As String
Dim r As Range
N = Cells(Rows.Count, 1).End(xlUp).Row
J = 1
For I = 1 To N
V = Cells(I, 1).Value
Set r = Nothing
Set r = Range("B:D").Find(V, After:=Range("B1"))
If r Is Nothing Then
Cells(J, 5).Value = V
J = J + 1
End If
Next I
End Sub
Well you can use this "big" array formula:
=INDEX($A$1:$A$10;SMALL(IF(NOT(COUNTIF($B$1:$B$2;$A$1:$A$10)+COUNTIF($C$1:$C$3;$A$1:$A$10)+COUNTIF($D$1:$D$2;$A$1:$A$10));ROW($A$1:$A$10)-ROW($A$1)+1;"");ROW(A1)))
Write the formula wherever you want to obtain the first an then copy down to obtain the others.
This is an array formula so dont forget to Ctrl Shift Enter
Depending on your Regional Settings you may need to replace field separator ";" by ","
This one is smaller and still works:
=INDEX($A$1:$A$10;SMALL(IF(NOT(COUNTIF($B$1:$D$3;$A$1:$A$10));ROW($A$1:$A$10)-ROW($A$1)+1;"");ROW(A1)))
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Could anyone give me advice on how to look up a row in a spreadsheet which matches two criteria, then change the data in specific Cells.
The data will be like this..
Reference Version date1 date2 date3
ABC1 1 11/12/2013
ABC1 2 31/12/2013
ABC2 1 12/12/2013
ABC3 1 12/12/2013
ABC1 3 01/01/2014
In VBA I wish to be able to find the row that matches the reference and the version number, then datestamp column 4 of that 1 unique row.
Any help would be really appreciated.
Many Thanks
Solving for a position for two criteria can be solved by this array formula (in this sample looking up ABC3 and 1 in A2:B6
This formula can be used in VBA to provide the position for the timestamp:
VBA Equivalent
Sub OneWay()
Dim lngRow As Long
lngRow = Evaluate("=MATCH(1,(A2:A6=""ABC3"")*(B2:B6=1),0)")
Cells(lngRow + 1, 4) = Now()
End Sub
or just:
Sub OneWay2()
lngRow = Cells(Evaluate("=MATCH(1,(A2:A6=""ABC3"")*(B2:B6=1),0)")+ 1, 4) = Now()
End Sub
Try this code:
Sub test()
Dim refToFind As String
Dim versToFind As String
refToFind = "ABC1"
versToFind = "1"
'address of first reference
Set Rng = Sheet1.Range("B2")
lastrow = Sheet1.Range("B" & Sheet1.Rows.Count).End(xlUp).Row - Rng.Row
For i = 0 To lastrow
If CStr(Rng.Offset(i, 0).Value) = refToFind _
And CStr(Rng.Offset(i, 1).Value) = versToFind Then
Rng.Offset(i, 4) = Now
End If
Next i
End Sub