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

How to insert > 137 no. pictures in excel file?

$
0
0
The 150 pictures in F:\PIC have to be inserted in attached excel file.
But it only works if F:\PIC has 137 pictures;
If the F:\PIC has more than 137 pictures VBA is not function.
Please help to revise the VBA.
(System: Win 10+ Office 365)
Folder F:\PIC is too large to be uploaded.

Extract data with one criteria and no duplicate

$
0
0
Dear All,

If i want to exctract data from worksheet "LIST" in column Item with certaint criteria in column Month and show the extracted data with no duplicate in worksheet "ectdata" starting from cell B7, is it possible to do this task with VBA? So everytime we change the criteria in worksheet "ectdata" on cell B4, tha list will be change accordingly.

For more detail I attach the Excel data.

Thank you for your kind helping.

Omegaboost
Attached Files

VBA if statement, please help

$
0
0
Hello community,

I need help with excel VBA formula , I have range with numbers ( and some of them with word "Absent" ) range is c5:bh18
I need formula to return value "7" if cell is number ( or >0 ) and if not number to return value "x"

and if possible on come cells ( MN / AC / AA / AB ) instead of "7" to give "5"


Can anybody help me please?

How to refresh dependent combobox list on focus on a userform

$
0
0
Hi, I'm a newb, apologies for any inadvertent faux pas.

I have taken over an old spreadsheet that a number of different cooks have had input into. I am attempting to 'fancy it up' with an input box etc. I'm pretty new to VBA (I've ordered a book but it hasn't arrived yet!) I'm really hoping somebody can help me.

The issue I'm having is this: on the original spreadsheet, there are two columns for input with data validation (lists from named ranges), and the second column options are dependent on the first, using the indirect function. I have created a userform, and a combobox works fine for the first column, I just designated the original data input cell as the 'control source', and the named range as the 'row source' in the properties. However, the second combobox, I've put the cell with the name of the range as the 'row source', and it almost works, the dropdown appears with options. The only problem is that the second combo-box options don't 'refresh' if a selection is changed in the first.

To try and put the problem more succinctly: every time the user makes a selection in the first combo-box, and the focus shifts to the second combo-box, the options in the second combo-box need to update.

If somebody could help me I'd be very grateful, I'm afraid I don't know enough to know if there is a really simple solution, I know I could code it all manually in VBA (if first dropdown selection is this, then options are....etc), but that seems like overkill.

Thank you very much kind people.

Need vba to split rows as new workbook with existing sheets and pivots!!

$
0
0
Dear experts

I have master sheet contains multiple country ledger names In P:P (GSIAP Ledger Name) . i want split rows as individual country names as new workbook along with pivot and all sheets save to target folder and name corresponding Accounted CUR in K:K on each ledger name.


i want split individual account name rows from three sheets RPT25&AR&AM and refresh two pivot tables.

In sheets RPT25 col P with formulas Q:AB, In sheet AR col B,In sheet AM Col B along with change data source & refresh on two Pivots&ESV ,LOB sheets....like

Conslidated file Japan,Korea,MEO Primary split as newworkbook saved as JPY,KRW,MEO.

find the attachment

output is like JPY - CON,KRW - CON,MEO - CON.xlsb files
Attached Files

Scrolling three listboxes simultaneously

$
0
0
Is it at all possible to scroll three listboxes simultaneously?

I need a listbox that can have different columns with different alignment. Given the very limited functionality of the VBA listboxes I'm trying to make three listboxes that can work together so that it looks like one list. Then I can have my first listbox with centered alignment, the second with left alignment and the third with right alignment.

It looks like I can overlap the listboxes so that only the third lisbox scrollbar is visible. So in effect only the third listbox can be scrolled but if it is scrolled the first and the second must scroll at the same time.

The three listboxes will always have the same number of entries.

Is there any suggestions out there that can possibly help?

I can't use VB controls as it is Excel 64bit and apparently VB controls (32bit) can't be used in Excel 64bit.

Macro to find sheet name with next button option in case of multiple sheet with same name.

$
0
0
Hi All,

Pls help in macro to find sheet name in excel with next button option in case of multiple sheet with same name. Found similar macro in below link but it is not showing next option in case of multiple sheet with same name. Can anyone help me in resolving the same?


http://www.excelforum.com/excel-prog...e-2-print.html

Get totals and remain for specific ID

$
0
0
Hello everyone
In my sample workbook I have two sheets .. Data sheet and the Expected Results sheet ..
In Data sheet I have clients that have specific totals (that should be paid) in column D .. and in column G the amounts that is paid ..
I need in the Expected Results sheet to prepare a report for those who didn't pay all the Total only .. as for who paid the total amount I didn't need to extract them ..
In other words if the value in column G is less than the value in column D then to deal with that row ..
For example :
The ID process 189 in second row of table has a total 90.000 and in column G there is a value 80.000 so he didn't pay all the total amount ..
and the same ID process pay another (second paid) in row 3 , he paid 5000 so the total is still unpaid completely
I have attached the expected results to illustrate the form of the report needed

Thanks advanced for help
Attached Files

top row dissappears when macro runs

$
0
0
hi
I have made a few macros and linked together ,on load data I have a header row wo-sd- staus-description-day ect,when I click the re arrange button it goes through the routine as should as copies all selected to sheet2,the only problem im having is the header row disappears sometimes it ends at the bottom of sheet2 and also disappears from top of load data and goes to usually around row 646-670
has any one any ideas what ive done please
cheers colin
Attached Files

Lookup, when found copy certain cells

$
0
0
I have a sheet with lots of data. I need it to look up a certain text in A:A. when found it needs to copy it to sheet 2. But it also needs to copy some other cells of sheet 1 to sheet 2. I added a excel sheet showing how the data is provided and on sheet 2 is showing how it needs to be arranged/ converted to. Only noted two items but sheet is in real has many many many more items/lines.
Attached Files

Saving a range of excel cells as a script file (scr.) without "Save As" prompt screen

$
0
0
I'm trying to write scripts in excel which can be then used in AutoCAD. So i have a range of cells in excel (column I) which i would like to save directly to a script file. I've found bits and pieces of code online and worked through it, however, i want the macro to save directly over the existing script file without displaying the save as prompt menu. This is the code i have so far which requires saving at the prompt menu. Any help would be much appreciated. I've attached the code below.

Sub SaveScriptFile()

Dim Cell As Range
Dim Filename As String
Dim Rng As Range
Dim RngEnd As Range
Dim scrFile As Integer
Dim Wks As Worksheet

Set Wks = Worksheets("Sheet1")

Set Rng = Wks.Range("I6")
Set RngEnd = Wks.Cells(Rows.Count, "I").End(xlUp)
If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Wks.Range(Rng, RngEnd)


Filename = Application.GetSaveAsFilename("C:\Users\New\Desktop\DraftScript.scr", "Script Files (*.scr),*.scr")
If Filename = "False" Then GoTo ExitSub


scrFile = FreeFile

Open Filename For Output Access Write As #scrFile
For Each Cell In Rng
Print #scrFile, Trim(Cell)
Next Cell
Close #scrFile

ExitSub:


End Sub

Multiple arrarys using for loops

$
0
0
Hello,First time vba'ing anything. My current vba is coded to make a 4X4 matrix on the range of A2. I was wondering how I would go about making another 4X4 starting from Range F2 using a for loop that takes the input from cell(1,2). I tired putting a for loop from L= 1 to num3 as seen. I just don't know how to set the range as well as the for loop.

Option Explicit
Option Base 1
Sub main()
Const nrow As Integer = 4, ncol As Integer = 4
Dim num1 As Integer
Dim num2 As Integer
num2 = Cells(1, 2).Value

num1 = Cells(1, 1).Value
Dim c(nrow, ncol) As Integer
For l = 1 To num2

Dim i As Integer, j As Integer
For i = 1 To nrow
For j = 1 To ncol
c(i, j) = i * 2 + j ^ 3 + num1

Next j
Next i
Next l
Sheets("sheet1").Select: Range("A2").Select
For i = 1 To nrow
For j = 1 To ncol
ActiveCell.Value = c(i, j)
ActiveCell.Offset(0, 1).Select
Next j
ActiveCell.Offset(1, -ncol).Select
Next i


End Sub

Inventory management with scanner

$
0
0
Good evening,
So I've been messing with excel to manage a inventory of roughly 10k worth of items. I am tracking PN/SN/location and other info I have an example of how the table will be formatted. I have gone through and uploaded most of the barcodes to the worksheet, what I'm trying to do is set up a inventory macro that as i scan the barcodes on the equipment excel will search find the barcode highlight the entire line green and let me scan the next item. Im also trying to get the search bar implemented into he spreadsheet some where around A1 for text and A2 as the search field that search the column H the idea would be to complete an entire inventory in hours instead of weeks. any help would be great. the scanner that i am using is a power scanner M8300
Attached Files

I need to create a reset button that will reset rows containing a specific value

$
0
0
So here is my dilemma, I've created a booking system for my B&B hotel and I need to find a way to delete (reset) all rows with data of my guests that have stayed and checked out of my hotel. It gets extremely frustrating to delete each cell to make room for more bookings as you can imagine. Below is a screenshot of my current excel sheet. I've managed to make a "Reset all stayed bookings" button on the top right of my sheet however I am stuck on the programming of the button in the VBA editor. What I need is to reset all rows containing the word "Hospedado" in column F (It's all in portuguese). However, column H/J/O/R/S/T has code in it and will be reset automatically if the other cells are blank so these must be left alone. I am very confident in excel code however it's my first time venturing into the VBA editor so help would be very much appreciated!

Best regards,
Andreas B.

Booking.png
Attached Images

Skip headline while merging csv file

$
0
0
Hi,
my vba code is inserting all csv files from a folder, but i would like to skip the headline, it will be perfect if the headline could be inserted the first time, and skipped for the rest of the files imported.

Code:

Sub Example12()
Dim MyPath As String
Dim FilesInPath As String
Dim MyFiles() As String
Dim SourceRcount As Long
Dim Fnum As Long
Dim mybook As Workbook
Dim basebook As Workbook

'Fill in the path\folder where the files are
'on your machine
MyPath = "c:\test"

'Add a slash at the end if the user forget it
If Right(MyPath, 1) <> "\" Then
MyPath = MyPath & "\"
End If

'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.csv")
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If

On Error GoTo CleanUp

Application.ScreenUpdating = False
Set basebook = ThisWorkbook

Dim nextRow As Integer
Dim wsTotal As Worksheet
Set wsTotal = basebook.Worksheets("sheet1")

'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 0
Do While FilesInPath <> ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop

'Loop through all files in the array(myFiles)
If Fnum > 0 Then
    For Fnum = LBound(MyFiles) To UBound(MyFiles)

        'open file
        Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))

        With wsTotal

            'activate if you want (optional)
            '.Activate

            'copy all the data on the sheet
            mybook.Worksheets(1).UsedRange.Copy

            'find the next empty row
            nextRow = .Range("A1").SpecialCells(xlCellTypeLastCell).Row + 1

            'select if desired (optional)
            '.Cells(NextRow, 1).Select

            'paste the data
            .Cells(nextRow, 1).PasteSpecial (xlPasteAll)

            'turn off copy mode
            Application.CutCopyMode = False

            'Do you really want to change the worksheet name?
            '.Name = mybook.Name
        End With

        'close file
        mybook.Close savechanges:=False

    Next Fnum
End If
CleanUp:
Application.ScreenUpdating = True
End Sub


[SOLVED] Read all the textboxes on a form into an array

$
0
0
Is there an nice short way of reading all of the textbox values on a form into an array? What I am hoping for is something like:

Code:

intCtr = 1
For Each each txtbx in TextboxCollection
intCtr = intCtr + 1
txtboxArray(intCtr) = txtbx.text
Next

?

Thank-you!

Set shortcut key from VBA

$
0
0
Hi all,

For any macro I can add a shortcut key to launch it,
but can I do it only from excel dialog window during select macros item?

I would like to add this properity by VBA for exaple calling macro saved into personal file and regarding to active workbook sets specific shortcut key to call another macro.

Is it possible?
Is this question is enough clear?

copy row based on specific value

$
0
0
i have an issue in copying the row based on single value. i have around 100 sheets and i need to copy the rows from each sheet by filtering a value. Can someone please help on facilitating this one?

Example:
Sheet1:


column1 column2 column3
address state city
address1 state1 city1
address2 state city2
address3 state city3


i need to copy the rows based on column value as state. my output should be like below:

column1 column2 column3
address state city
address2 state city2
address3 state city3

and i need to copy the name of my sheet to my new sheet.

Thanks

Ensure user fill up all necessary cells before proceed for saving

$
0
0
Hi all,

I know most likely my condition below have to use specific system to work but is there any possibility with excel macro?
I have a file for user to feedback daily. The condition as such:

Column L to be updated in day 1, Column M to be updated in day 2.
Column L allow user to choose YES or NO only, Column M allow user to choose Completed, WIP, Deferred only.

1. If task accepted (Column L) in day 1, no further action in Remarks (Column N).
2. If task accepted (Column L) in day 1 but Deferred in day 2, user have to provide reason in Remarks (Column N) before proceeding next. If WIP, no further action in Remarks.
3. If task not accepted (Column L) in day 1, user have to provide reason in Remarks (Column N) straight away before proceeding next.
4. If task not accepted (Column L) in day 1 with remarks but completed in day 2. No further action required.
3. If task no status updated in Column L, user have to provide reason in Remarks (Column N) straight away before proceeding next.
By the way, is there any method not to allow user to skip this macro function during file access? and, have to ensure all condition stated above are meet before proceed for saving?
Attached Files

Problems w/Indirect Vlookup and Pasting to Last Column

$
0
0
Evening, Gurus.

The code below works as written now, but does not allow for variables such as different number of Columns used or a different workbook name. I've searched here and Google to try and find solutions, and did manage to correct a few of my problems, but those two still have me stymied. I notated the problems in the code below. I also attached a short and non-sensitive version of the workbook to this message so you can review the activity. I appreciate any help you can offer:

Code:

Sub Add_Vendor_Columns()
    Dim R As Range
    Dim WS As Worksheet
    Dim WB As Workbook
    Dim LastCol As Long
    Set WB = ActiveWorkbook
    Sheets("All Data").Copy Before:=Sheets(2)
    ActiveSheet.Name = "VENDOR COLUMNS"
    Range("A:A,E:E,G:U").Delete Shift:=xlToLeft
    Cells.Select
ActiveWorkbook.Worksheets("VENDOR COLUMNS").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("VENDOR COLUMNS").Sort.SortFields.Add Key:= _
        Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets("VENDOR COLUMNS").Sort
        .SetRange Range("A1:D" & Cells(Rows.Count, "A").End(xlUp).Row)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    ActiveSheet.Range("A1:D" & Cells(Rows.Count, "A").End(xlUp).Row).RemoveDuplicates Columns:=1, Header:= _
        xlYes
    Columns("E:BZ").NumberFormat = "$#,##0.00"
    Range("E1:BZ1").NumberFormat = "@"
    Set R = Range("E1")
   
'This will cause a problem if I save the macro in my PERSONAL.XLSB workbook.
'How would i write this line so it is looking at worksheets in the ActiveWorbook?
    For Each WS In ThisWorkbook.Worksheets
   
    If WS.Name <> "All Data" Then
    If WS.Name <> "VENDOR COLUMNS" Then
        R.Value = WS.Name
        Set R = R(1, 2)
    End If
    End If
    Next WS
   
'I tried to find the last column with data for use in copying my formula
'to the last used column.  Haven't been able to make it work yet.
    LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
   
'This is my failed attempt to tell the vlookup to look in the ActiveWorkbook,
'whatever the name, on the sheet named in cell E1.  I get an "Application
'DEfined or Object Defined error.  No luck figuring this out yet.
'I rimeed the line for testing purposes
    'Range("E2").FormulaR1C1 = _
        "=VLOOKUP(RC1,INDIRECT(" & ActiveWorkbook & "&R1C&""'!$B:$T""),11,FALSE)"
   
'Same formula as above, but this would not work if the Workbook were named something else.
'I can't figure how to make the indrect vlookup work in the ActiveWorkbook, no matter
'what the name of the workbook is.
    Range("E2").FormulaR1C1 = _
        "=VLOOKUP(RC1,INDIRECT(""'[PM Vend (Test).xlsm]""&R1C&""'!$B:$T""),11,FALSE)"
    Range("E2").Copy
   
'Run-time Error 1004.  Method "range" of object "Global" failed.
'I am trying to get the script to paste the formula I just entered in cell E2
'over to the last used column.  I rimmed the line for testing purposes.
    'Range("E2:" & LastCol & "2").Select
   
'The line below call out the specific range for this test, but wouldn't work if there
'were more columns on the worksheet.
    Range("E2:H2").Select
   
    Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Selection.Copy
   
'I need the line below to copy the formulas just entered down to the
'last used row and last used column.  I know the formula to paste to the
'last used row, but no idea how to do both.  This is why I dimmed LastCol
'at the beginning, and tied to set it later, but I still can't make it work
'in my script.
    Range("E2:H7").Select
   
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.Replace What:="#N/A", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Application.CutCopyMode = False
    Range("A1").Select
End Sub

Attached Files
Viewing all 49926 articles
Browse latest View live