Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all 49946 articles
Browse latest View live

VBA datevalue

$
0
0
Hi,
I import data into the attached file but the date comes in as text, I can use the datevalue formula in another column and it works fine but I am having difficulty converting it as part of vba code, I keep getting an error, Can anyone shed any light of this?, It needs to convert the text date in column A in sheets X08 & X47.
Many Thanks
Johnny
Attached Files

Type mismatch with application.search

$
0
0
I am getting a type mismatch when using application.search- the relevant bit is in bold:

Code:

For i = 1 To UBound(w, 1)
    If Not Application.IsNA(Application.Lookup(34 ^ 88, Application.Search(g, w(i, 2)))) Then
        y = y + 1
    End If

G is an array. I am not sure why I cannot use it in this way and am getting the type mismatch.

When I do the following the code works fine:

Code:

For i = 1 To UBound(w, 1)
    If Not Application.IsNA(Application.Lookup(34 ^ 88, Application.Search(Range("Valid_List"), w(i, 2)))) Then
        y = y + 1
    End If

This works fine even when I transpose g into the (one column) named range and then re run it.

However, for unrelated reasons I cannot use that as a solution.

Is there a way round this?

Thanks

Finding Matches for Items in two Spreadsheets

$
0
0
I am trying to find matches for alpha numeric codes which show up in two spreadsheets.
I have a master list of names below with relevant codes attached to them.
For instance:

Name Code
Jake ABC, CB1, B23
Matt ABC, B23, D21
Sarah ERT, EF, D21D

I have a second spreadsheet with a partial list of the codes below

Code
ABC
CB1
D21
EF
D21D

Basically if any of the elements in Col 2 in the first spreadsheet match any elements within Col 1 in the second, I would like it to be indicated in Col 3 in the first spreadsheet, like so:

Name Code Matches
Jake ABC, CB1, B23 ABC, CB1
Matt ABC, B23, D21 ABC, D21
Sarah ERT, EF, D21D EF, D21D

Wondering what the best way to go about doing this?

Add Search capabilities to this current Workbook

$
0
0
Hi All,

Wanted to know if it's possible to add a search button to this workbook... Assuming there are 100's of people in the list, wanted to be able to do a search

Is it possible with this type of setup?



HR Dashboard Master V3.xlsm

John

Divide a range by left to active cell

$
0
0
I am trying to build a button that will take the column to the left of the active cell I have selected and divide each line item by the one cell to the left of my active cell and multiply this ratio by a cell that will never move on the sheet.

Any ideas of the best code for this?

thank you

loop through a colums changing values conditionally

$
0
0
Hi all,

I can change the contents of a cell like this:

Code:

Private Sub CommandButton1_Click()
Dim moon As Variant

newvar = "aaa"

If Range("A1").Value = "a" Then Range("A1").Value = newvar

End Sub

In the example if the letter a is in A1 I can change it to aaa.My idea is to loop through a column and the code finds a specific value,it will then change it for another value.
I have not had much experience with loops so I am asking is this possible and if so could somwone show me.So far my loops have not worked.


Kind Regards
TG

Fetch specific range lying between two cell values.

$
0
0
Hi:

In my folder, there are about 350 files with similar structure but varying rows ranging from 300 to 400. In all the files, Column B has TIME values in the format hh:mm:ss, for example, 10:01:00. In the address bar, the time values appear as 10:01:00 AM, 15:11:00 PM, etc. I want to fetch all the rows between two values 15:11:00 and 15:30:00 and save this data as a new file with original file name but adding a suffix 1. For example, if the original (big) file is WorkbookA.xls, then the newly created file will be WorkbookA1.xls. File format is xls. I have tried to do this by Macro Recorder but could not. Can someone help me with a macro for this task?
PS: All files have columns A:H

Split one string in cell after second semicolon

$
0
0
HI I made a new thread here. I have all the strings text in one cell H8. I want it to be separated after the second semicolon to next row and down.
I have attached a test sheet so it more easy to see.
Sincerely
Abjac
Attached Files

Error opening userform (clicking button)

$
0
0
Hello,

Thank you for your time and expertise!

The file: ExampleFile.xlsm - image of error segment below

The whole workbook is intended to be a vacation calendar for a company department, where employees can input their vacation requests. When using the macro, the error appears to occur at the "RetractRequestForm.show", but I think the actual error is located somewhere in the RetractRequestForm - Initialize section. Here is the section: RetractRequestForm.Initialize.JPG

This is intended to load the visible rows of a table (filtered) into a multicolumn listbox.

I appreciate your time and thoughts.

Compound Interest

$
0
0
Hello,

Can anyone help me?

I need a formula in Excel that calculates compound interest

Principal sum of $5m
Yielding a weekly return of 8%
So returns accrue every 5 banking days (with no withdrawals)
Minus a weekly commission fee of 5%
Giving the NET monthly compounded result per month for 10 banking months.

A week is 5 banking days and a month is a banking month of 20 days.

Thanks very much!

Helen

Code for data extraction

$
0
0
Dear All,

Kindly assist a friend.

I have a master workbook. Column 'G' has dates in the format 'dd/mm,yyyy.
I regularly extract data from the master sheet using dates; say filtering data between 1/11/2014 and 30/11/2014 and copy it to a new sheet. I know I can use a formular but since this is a routine task, a macro will do.
Kindly assist me.

VBA Define Date Variable as Filter Criteria

$
0
0
Hello to all,

I am a beginner at VBA and I trying to make a Workbook that will filter the raw data of one sheet based on some criteria and the copy the matching data to summary sheet. I have managed to work it out for the some of the criteria but I stacked on how to define a Date criteria and sort it out. Also, I have a field in Date Timestamp format (YYYY-MM-DD HH:MM:SSTX) which I want also to use as filtering criteria but to input it as DD-MM-YYYY.

I attach the file with an example and the VBA code.

Any help will be greatly appreciate.

Summary Date.xlsm

Thank you all.

Please solve the Error : Expected List separator..

$
0
0
Hi,

I am getting an compile error expected List separator in the below line:

ColumnLetter = Mid(rCell, InStr(rCell , “$") + 1, InStr(2, rCell, “$”) – 2)

I am novice to excel.

Please can anyone help on this one.

Regards

Please solve the Error : Expected List separator..

$
0
0
Hi,

I am getting an compile error expected List separator in the below line:

ColumnLetter = Mid(rCell, InStr(rCell , “$") + 1, InStr(2, rCell, “$”) – 2)

I am novice to excel.

Please can anyone help on this one.

Regards

Random unique numbers

$
0
0
I hope this is the correct place to post this but I really do need help.

I need to write a programm for excel vba and since we just now started to learn how to write code in vba im having issues. This is how it has to work:
I click on a button which generates 7 unique numbers(5 in a range of 1-50 and 2 in a range of 1-8) and puts them in textbox.

I've tried searching for a solution since this has been asked a thousand times I assume but the ones i've found seems really difficult so I havn't been able to replicate any of them. Any help would be highly appreciated.

RANDBETWEEN Excel Function in Macro

$
0
0
Hi there!
I need some help or advice...
I have a vb code below which generate numbers in desired cells according to the range provided in the code.
Code:

'-------STEP 2---------
Sub FillRandomNumbers()
 Range("BH03").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(45,65)"
 Selection.AutoFill Destination:=Range("BH03:BH10"), Type:=xlFillDefault
 Range("BH03:BH10").Select
 
 Range("BH13").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(45,65)"
 Selection.AutoFill Destination:=Range("BH13:BH20"), Type:=xlFillDefault
 Range("BH413:BH20").Select
 
 Range("BH23").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(45,65)"
 Selection.AutoFill Destination:=Range("BH23:BH30"), Type:=xlFillDefault
 Range("BH23:BH30").Select
 
 Range("BH33").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(45,65)"
 Selection.AutoFill Destination:=Range("BH33:BH40"), Type:=xlFillDefault
 Range("BH433:BH40").Select


'-------STEP 3---------

 Range("BI3").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(45,60)"
 Selection.AutoFill Destination:=Range("BI3:BI10"), Type:=xlFillDefault
 Range("BI3:BI10").Select
 
 Range("BI13").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(45,60)"
 Selection.AutoFill Destination:=Range("BI13:BI20"), Type:=xlFillDefault
 Range("BI13:BI20").Select
 
 Range("BI23").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(45,60)"
 Selection.AutoFill Destination:=Range("BI23:BI30"), Type:=xlFillDefault
 Range("BI23:BI30").Select
 
 Range("BI33").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(45,60)"
 Selection.AutoFill Destination:=Range("BI33:BI40"), Type:=xlFillDefault
 Range("BI33:BI40").Select


'-------STEP 4---------

 Range("BJ3").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(25,47)"
 Selection.AutoFill Destination:=Range("BJ3:BJ10"), Type:=xlFillDefault
 Range("BJ3:BJ10").Select
 
 Range("BJ13").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(25,47)"
 Selection.AutoFill Destination:=Range("BJ13:BJ20"), Type:=xlFillDefault
 Range("BJ13:BJ20").Select
 
 Range("BJ23").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(25,47)"
 Selection.AutoFill Destination:=Range("BJ23:BJ30"), Type:=xlFillDefault
 Range("BJ23:BJ30").Select
 

 Range("BJ33").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(25,47)"
 Selection.AutoFill Destination:=Range("BJ33:BJ40"), Type:=xlFillDefault
 Range("BJ33:BJ40").Select



'-------STEP 5---------

 Range("BK3").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(240,480)"
 Selection.AutoFill Destination:=Range("BK3:BK10"), Type:=xlFillDefault
 Range("BK3:BK10").Select
 
 Range("BK13").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(240,480)"
 Selection.AutoFill Destination:=Range("BK13:BK20"), Type:=xlFillDefault
 Range("BK13:BK20").Select
 
 Range("BK23").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(240,480)"
 Selection.AutoFill Destination:=Range("BK23:BK30"), Type:=xlFillDefault
 Range("BK23:BK30").Select

 Range("BK33").Select
 Selection.FormulaR1C1 = "=RANDBETWEEN(240,480)"
 Selection.AutoFill Destination:=Range("BK33:BK40"), Type:=xlFillDefault
 Range("BK33:BK40").Select
 
 End Sub

Code working well but when I'm clicking on the some cell from the range it show me formula (for instance: =RANDBETWEEN(45,65)) in the formula field even I've deleted the vb module.
I need that formula will not appears any more after macro finished to run and all tables will be filled with the numbers. The best solution will be possibility to delete the macro after it ran and all numbers stay as is in the desired tables.
Thank you in advance,
Igor

I need to subtotal times from a list where they overlap.

$
0
0
I have a column (M) that the contents are the result of subtracting a cell in column C from Column K. Now some of these numbers are positive and some are negative (#####). They are all the difference in start and stop times. These times are the start and stop of computer jobs and some run concurrently and some run after a break. So, you might have Job1 that runs from 09:00 to 09:15 while Job2 runs from 09:10 to 09:20. Essentially they took together 20 min to run (what I want) while if you added the times of each you would come up with 25 min (not what I want). Then you might have a 2 hour break and Job3 runs for 30 min, then and hour later Jobs 5-6 run from 12:00 to 14:30, 2.5 hours. These jobs are grouped in any one of 6 categories.*

What I want to get is the "real" time it took to run all the jobs in each category and I can't get my mind around how to do it. In the example above the correct answer would be 2:30 + 0:30 + 0:20 or 3 hours and 20 minutes. I have all this information in a spreadsheet output by the software that runs it, so I can sort by category, then start time to get a baseline. I have to do this every day at end of day, so I really don't want to sift through 650 rows or so to figure it out manually.

Thanks for any help, I'm lost

Colour visible cells in a loop VBA

$
0
0
Hi, I have a column G of numbers 1 to x. I then have another macro which hides certain rows so that instead of 1,2,3,4 you may get 1,2,3,16. i then want to identify when there is a break in the numbers e.g. 4,5,6,7 15. (a break of more than 2) which should then colour a corresponding cell in column B. Currently it loops every cell i think and therefore doesn't recognise the jump between numbersThanks for your help

Code:

Private Sub CommandButton1_Click()[/SIZE]
Dim intRows As Integer
Dim intCols As Integer
Range("G37").Select
 
 'would like to use ActiveCell.SpecialCells(xlLastCell).Select but this often changes to a random cell instead of the last visible cell in column G
 
 'determine how many rows and columns to work on
intRows = Selection.Row
intCols = Selection.Column
 
intColour = 2
 
For i = 2 To intRows
    For j = 7 To intCols
       
        'change colour of first cell on each row
        If j = 2 Then Cells(i, 1).Interior.ColorIndex = intColour
       
        If Not Cells(i, j).EntireRow.Hidden And Not Cells(i, j).EntireColumn.Hidden Then
           
            Cells(i, j).Select
           
            'see if value same or different, then colour cell accordingly:
            If Cells(i, j).Value > Cells(i - 1, j).Value + 2 Then
                intColour = (intColour + 1) Mod 55
                'avoid background colour being same as text (black in this case)
                If intColour = 1 Then intColour = 2
                Cells(i, j - 5).Interior.ColorIndex = intColour ' no selection needed to do this
            Else
                Selection.Interior.ColorIndex = Cells(i, j).Interior.ColorIndex ' this still needs to be solved, not sure of your intent
            End If
           
        End If
       
    Next j
Next i
End Sub

I need to subtotal times from a list where they overlap.

$
0
0
I have a column (M) that the contents are the result of subtracting a cell in column C from Column K. Now some of these numbers are positive and some are negative (#####). They are all the difference in start and stop times. These times are the start and stop of computer jobs and some run concurrently and some run after a break. So, you might have Job1 that runs from 09:00 to 09:15 while Job2 runs from 09:10 to 09:20. Essentially they took together 20 min to run (what I want) while if you added the times of each you would come up with 25 min (not what I want). Then you might have a 2 hour break and Job3 runs for 30 min, then and hour later Jobs 5-6 run from 12:00 to 14:30, 2.5 hours. These jobs are grouped in any one of 6 categories.*

What I want to get is the "real" time it took to run all the jobs in each category and I can't get my mind around how to do it. In the example above the correct answer would be 2:30 + 0:30 + 0:20 or 3 hours and 20 minutes. I have all this information in a spreadsheet output by the software that runs it, so I can sort by category, then start time to get a baseline. I have to do this every day at end of day, so I really don't want to sift through 650 rows or so to figure it out manually.

Thanks for any help, I'm lost

How to subtotal times that overlap

$
0
0
I need to write a subroutine that will subtotal overlapping groups of times when I click a button. Here is a small example:

Capture.JPG

So, as you can see the times overlap in some instances. When they do I want to group those into one block and report the entire time it took to do Proj1, in this case 03:11. For example the first block ran from 7:34 to 7:49 and the second block ran from 8:38 to 8:48 and so on. I want to be able to click on a button labeled "Proj1) and have the result display in a cell. There are typically about 6 project groupings and around 600 lines so I don't want to have to go through this manually every night as I'm doing now. I have some experience with VBA but have been away from it since Office 2003 was the new kid on the block, so I'm rusty and need a kick start. This is running Office 2010 on Windows 7 Pro.

Thanks for any help

-Jim
Viewing all 49946 articles
Browse latest View live