Excel cells matching in VBA [closed] - vba

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 want to use a number in a cell of my main excel sheet and use it to search for a specific line in another excel file that start with this number. After, the program needs to use the value of a specific cell in this line for a cell in my main excel sheet.
EX : value of the first cell in my sheet : 6.02 . Now the program need to find this value in a column of another file. The line that start with 6.02 contain a cell with the value dog. The value dog need to go inside a cell next to the first one that contain 6.02.
I need your help because I know nothing about VBA. I'm starting today!
Thank you very much !!

You can accomplish this with a VLOOKUP between two books. The guts of the equation are below. You wont actually type in the '[book2]SheetName' portion, this will need to reflect the name of your other workbook and the sheet that you are looking at within that book.
A2 = Look up value (in your example 6.02)
X1 = Column the return value is (in your example "dog")
X2 = Column Index Number (Of if you are not starting from A it represents the (Index Col of Value - Index of Look up Value) + 1
=VLOOKUP(A2,'[Book2]SheetName'!$A$X1,X2,0)

Related

Excel VBA Macro - find text in cell one, replace value in adjacent cell [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
Working on a vendor's sales document provided by a grocer, which lists the number of units they sold. Issue is that their excel sheet and the way they record sales (which I cannot change) doesn't differentiate between single bars sold and boxes sold - so some rows state "Mint Bar" = 1 sold and some state "Mint Bar Box" = 1 sold. The unit values are the same in the sheet, but the "box" should really = 12 (since a box is 12 units, not just 1).
The second issue is that every time "box" appears that value needs to be n*12 (so 1box*12 = 12 bars).
Thus, I am looking for some code to help me out. I know this is easy in SQL and have less experience running excel macros.
--
Fixed:
Where the Boxes appear in D2, D6, D8, etc:
=if(Cell="Box", 12*D2, 12*D6, 12*D8)
Drag formula down for all the rows in the sheet.
do you have to do this in a macro? I would just add another column that says
=if(Cell="Mint Bar Box", 12, 1)

Dynamic Reference to Sheets: VBA [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'm new to VBA and need some help with a macro I'm trying to program
I have 31 sheets representing days of the month and a "Master" tab with the current date (this is used for data input). I want the person doing the data entry to be able to sign and date the sheet, click a button and copy paste the values of the initials into the appropriate date tab. I have mined and manipulated data using the INDEX/MATCH functions with an embedded INDIRECT reference, but I don't know how to do this in VBA.
Example, I'm doing data entry for Aug 14th. The master tab with retrieve all of August 14th's data. After inputting, I want to click a button on a userform and it will copy and paste that into the appropriate "day" tab... in this case, the tab named "14"
Thanks for any help! I'm learning, but getting there.
You just need to refer to the sheet name as a format of the date. For example:
Function TheSheet(ByVal dt As Date) As Worksheet
Dim ws As Worksheet
Set ws = Worksheets(Format(dt, "dd"))
If Not ws Is Nothing Then Set TheSheet = ws
End Function

How to use Auto filter criteria from a cell reference on another workbook [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
Need help in using vba to auto filter columns in a workbook but the filter criteria is in a cell reference on another workbook. To Start, i have 2 workbooks, the first is the report template where the macro is entered and the other is the data file that needs to be filtered.
You can reference reference cells in the (closed) template workbook in your Autofilter VBA statement. ExecuteExcel4Macro is of help here, permitting to evaluate a reference to another, closed workbook the same way it would be typed in a formula.
For example, to autofilter a range by cell B5 of the control sheet in the report template:
myRange.AutoFilter 1, ExecuteExcel4Macro("'C:\myPath\myfolder\[Report.xltx]control'!R5C2")
Notice that ExecuteExcel4Macro requires RC-style addresses, so use R5C2 for B5, R5C3 for C5 and R5C4 for D5...

Excel VBA - If Then Replace [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 8 years ago.
Improve this question
I am very new to VBA and I have read so much on the If-Then-Replace that I think I'm confusing myself. Within my worksheet I have two columns that come in with more data than what I need and I have to get it pared down in order to concatenate it.
Column H (Header) has the following data in each cell: Network: Series: Episode : Data
Column J (Header) has the following data in each cell: Network: Type: Type2: Type3
I run a text-to-columns to get it down to have the Network in 1 column and the Series in the 2nd column.
What I need is a Search in Column J for "specific network". If this is true then replace the network in Column H.
Question: Will I need to also run a text-to-columns in Column J to get a 1:1 comparison?
Question: Can you help me with the VBA code to do the Find-If-Then-Replace?
Thank you so much!
This should do what you're looking to do... If it works for you, please mark the answer as accepted by clicking the checkmark to the left.
Sub Freplace()
dim i as int
dim s as string
i = 1
s = "specific network"
Do until Cells(i,10).Value = ""
If Cells(i,10).Value = s Then Cells(i,8).Value = s
i = i+1
Loop
End Sub

Automatic excel cell fill up from another sheet [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 8 years ago.
Improve this question
Here's the situation:
I have two excel sheets.
The first sheet contains a table of product codes and product descriptions (Two columns A and B).
I have a second sheet where someone is supposed to enter the product code and automatically have the next cell fill up with the product description and the cell next to it with the time.
I was wondering if that's do-able without VBA? If so, can someone give me start.
Best,
You could have the first cell that you want to auto fill have an IF statement, where if the cell has no value, nothing happens, and anything other than that gets a calculation.
Using A2:B100 as a Range if you have a header Row. Adjust to your own needs, of course.
IF FUNCTION
'IF (condition, result if true, result if false)'
VLOOKUP FUNCTION
'VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)'
=If($A1 = "", "", VLOOKUP(A1,Sheet1!$A$2:$B$100,2))
The next cell over would have something similar:
=IF($A1 = "", "", NOW())
This will get you the time. You will also have to have the cell format set to Time.
There is a problem with that. The screenshot below illustrates it.
It will just keep refreshing with the current time over and over. I would use a bit of VBA to solve that by setting the value property instead of a formula.
Sheets("Sheet2").Cells(row,col).Value = Now()
You could copy and paste the value into another cell. Just the value. Not the formula.
Or you could check out this article: about generating Time Stamps.
edit: included VBA solution