convert Arabic saved Excel file to English - excel

I have received the attached Excel file from my friend who wishes to convert into English(US).
While there is no Arabic text but only numerals, I am not able to work. If I copy and paste the cells into a new workbook, even the formats are saved. The numbers have spaces in between and I tried using Trim function.
Even if the spaces are deleted manually, the number is still shown on the right side of the formula bar. Pls help.

There are two settings regarding text direction and column layout within File, Option.
file, options, advanced, display, default direction.
... and,
file, options, advanced, display options for this worksheet, show sheet right to left

One way is to print to PDF, then open the PDF and export as spreadsheet. It's not perfect but I haven't found any of the other ways to reverse this.
This (https://www.extendoffice.com/documents/excel/1763-excel-change-sheet-direction.html) seemed helpful and may work for others but did not work for me, nothing did - the workbook that I had may have somehow been locked in this regard (I'm not sure if that's a thing but nothing I tried was correcting it)
Another possible solution is to open a new workbook with the correct structure and run a VBA script that copies, one sheet at a time and one cell at a time, from the Arabic-orientated workbook to the Western orientation. If there are graphs it will get a bit more tricky with putting them in the correct place but I'm sure for each sheet you could loop through each object, copy it and paste it in the other workbook and then move them around once there. Again not an easy or ideal solution, but a solution.
Here is a very simple implementation I'm using. It could be written in a more sophisticated way with objects, etc but this gets the job done. To use this, close all workbooks. Open the workbook you want to copy from. This is workbooks(1). Then open a new, blank workbook. Alt + F11 to bring up the VBA editor, add a module to your project and paste the code below.
Run step01, this creates the sheets in your new workbook.
In the new workbook, delete all default sheets - Sheet1, Sheet2 and Sheet 3.
Run step02. It can take some time as it's a slow method activating different workbooks. This will loop through every sheet, find the last cell and then loop through every cell. It will copy it, and paste it in the correct row order but in reverse column order in the new workbook.
Sub step01_create_sheets()
'create sheets in other workbook
Workbooks(1).Activate
For k = 1 To Workbooks(1).Sheets.Count
Workbooks(1).Activate
Workbooks(1).Sheets(k).Activate
val1 = Workbooks(1).ActiveSheet.Name
Workbooks(2).Activate
Workbooks(2).Sheets.Add(, Sheets(Sheets.Count)).Name = val1
Next k
End Sub
Sub step02_copy_sheet1()
Workbooks(1).Activate
Sheets(1).Activate
sheet_count = Workbooks(1).Sheets.Count
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For m = 1 To sheet_count
Workbooks(1).Activate
Sheets(m).Activate
row_count = Range("a1").SpecialCells(xlCellTypeLastCell).Row
col_count = Range("a1").SpecialCells(xlCellTypeLastCell).Column
For k = 1 To row_count
For j = 1 To col_count
Workbooks(1).Activate
Sheets(m).Activate
val2 = Cells(k, j).Formula
Workbooks(2).Activate
Sheets(m).Activate
Cells(k, col_count - j + 1 + 1).Formula = val2
DoEvents
Application.StatusBar = "Sheet " & m & " of " & sheet_count & " ; Row " & k & " of " & row_count & "; Column " & j & " of " & col_count
Next j
Next k
Next m
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

Related

VBA- How to sort worksheets based on a number on their name?

I am new and I am working in a VBA - Excel Project.
My project has some Sub-projects, lets call them A,B,C...
Through VBA code and some actions I create new sheets that are called A-item-1, A-item-2 or B-item-1 or with C.
The thing is that I am creating these sheets by copying a template and printing it before the next letter.
For example, B-item-3 is created copying my B-item-template and printing it before C sheet.
Now, the way the program works you can create B-item-1, B-item-4, hit the button and it will create them.
If after that you want to create B-item-2, as the program puts it before C you will have this:
A,B,B-item-1,B-item-4,B-item-2,C (this is my workbook)
And I am thinking on a code to rearrange only "B-item-X" sheets.
As far as i know i should put these sheets in an Array.
Then i should, somehow, get the number from every sheet to a variable.
And then compare with a for these sheets and if the number is less than the sheet i am comparing it to, move that sheet.
I think it could look like this?
1st - Determine the Range of sheets I want to rearrange
2nd - Somehow extract the number of each "B-item-X" sheet
3rd-->
For i=1 to Range of sheets -1
For j= i + 1 to Range of sheets
if The number on the name of the (j) Sheet is < The number on the name of the (i) Sheet then
Sheets(j).Move before:= Sheets(i)
End if
Next j
Next i
I hope it is easy to understand what i want to do. If not, hit me up and i will try to explaint it with more details. I hope someone can help me. Thank you very much.
Edit:
The way the program works. The user writes an input and based on that I have a non visible chart in which i write 0 or 1 depending on the input of the user. Then the program creates the ITEM sheet if it sees a 1 on the chart.
As an example, for the 20 items i can create:
The user puts YES (1 in the Chart) on ITEMS 1,7 and 15 and presses the button OK.
The program creates them and you would have these sheets:
A,B,B-item-1,B-item-7,B-item-15,C,D...
But the program is still used for next Batches, lets say.
So the next day the user puts YES on the item 9. The program will create the "B-item-9" sheet before C sheet but it will be put after the "B-item-15" sheet because it was already crated the day before that.
The thing is i do not know how to move them to the right place when creating them nor do i know how to rearrange them...
Try this
Sub SortSheetsTabName()
Dim scrUpdating As Boolean: scrUpdating = Application.ScreenUpdating
Application.ScreenUpdating = False
Dim i As Long, j As Long
Const txtBefNum As String = "B-item-"
With ThisWorkbook
For i = 1 To .Sheets.Count - 1
If .Sheets(i).Name Like txtBefNum & "*" And _
IsNumeric(Mid(.Sheets(i).Name, Len(txtBefNum) + 1)) Then
For j = i + 1 To .Sheets.Count
If .Sheets(j).Name Like txtBefNum & "*" And _
IsNumeric(Mid(.Sheets(j).Name, Len(txtBefNum) + 1)) Then
If CLng(Mid(.Sheets(i).Name, Len(txtBefNum) + 1)) > _
CLng(Mid(.Sheets(j).Name, Len(txtBefNum) + 1)) Then
.Sheets(j).Move before:=.Sheets(i)
End If
End If
Next j
End If
Next i
End With
Application.ScreenUpdating = scrUpdating
End Sub
This will sort all worksheets that have a name starting with 'B-item-' according to the number in their name following that text from smallest to largest.

Excel Macro check if cell is empty and search specific word in column

Guy, I am beginner for VBA language, and I have a question to stuck on it.
How to make a macro script to check if ANY rows of column B is input word of "C" AND ANY rows of column C is empty, then it will trigger to highlight this row with color and prompt up the message box to remind user to correct it.
Also, the column D is using the formula and cell by cell method to check the above requirement.
=IF(ISBLANK(B4),"",IF(OR(B4="C",B4="O"),IF(AND(B4="C", ISBLANK(C4)),"WARNING: Case Closed! Please Write Down Resolution!",""),"ERROR: Invalid Value - Status! Please Input The Right Value!"))
For example, the row 4 meet up requirement and affected.
Is there way to do so?
Please help. Thanks.
UPDATE:Thanks Variatus!
When I save the file, it prompt up this message box. What can I do? Thanks.
Macro Screen
Error
Under normal circumstances you would be asked to show more of an own effort before receiving help on this forum, including from me. But apparently circumstances aren't normal. So, here we go. Paste this procedure to a standard code module (it's name would be a variation of Module1 by default).
Option Explicit
Sub MarkErrors()
' 283
Dim Spike() As String
Dim i As Long ' index of Spike
Dim Rl As Long ' last used row
Dim R As Long ' loop counter: rows
Application.ScreenUpdating = False
With Sheet1 ' this is the sheet's CodeName (change to suit)
.UsedRange.Interior.Pattern = xlNone ' remove all existing highlights
Rl = .Cells(.Rows.Count, "A").End(xlUp).Row
ReDim Spike(1 To Rl)
For R = 2 To Rl
If Trim(.Cells(R, "B").Value) = "C" Then
If IsEmpty(.Cells(R, "C")) Then
.Range(.Cells(R, "A"), .Cells(R, "D")).Interior.Color = vbYellow
i = i + 1
Spike(i) = "Row " & R
End If
End If
Next R
End With
Application.ScreenUpdating = True
If i Then
ReDim Preserve Spike(1 To i)
MsgBox "Status errors were found in the following entries:-" & vbCr & _
Join(Spike, "," & vbCr), vbInformation, "Corrections required"
End If
End Sub
Pay attention to the specified worksheet Sheet1. This is a CodeName, and it is a default. Excel will create a sheet by that name when you create a workbook. The CodeName doesn't change when the user changes the tab name but you can change it in the VB Editor. It's the (Name) property of the worksheet.
Install the procedure below in the code sheet of Sheet1 (not a standard code module and therefore not the same as where you installed the above code. This module is created by Excel for each sheet in every workbook. Use the existing one.
Private Sub Worksheet_Activate()
' 283
MarkErrors
End Sub
This is an event procedure. It will run automatically whenever Sheet1 is activated (selected). So, under normal circumstances you shouldn't ever need to run the first procedure manually. But I've already talked about circumstances. They aren't always normal. :-)

Formula referencing from other workbooks

I'm quite new to VBA and I'm having trouble debugging a certain code. What I want is a cell formula that has the formula link to another spreadsheet. However, I want to add cells from multiple workbooks. For example, if we had workbook1 and workbook 2. I want in cell F10 in final workbook to have formula reading '[workbook1]Sheet1'!!F10' + '[workbook2]Sheet1'!!F10'
I like to make the formula as flexible and have the following conditions
I like to have an open directory that lets me select excel files that I want as part of the formula
I can add as many external spreadsheets as possible
The final spreadsheet initially will have zeroes in them. I want to replace this with a formula link.
How i decided to code this is by first replacing the zero cell of the final workbook with cell F10 of first excel file selected from a directory. Once this step is done, any additional workbooks selected from directory will add on as an extra formula link to the cell. Below is a code I attempted but I can not figure why it doesn't work. Could anyone please let me know what is going wrong? Thanks.
Sub Sum_workbooks_Form()
Dim FileNameXls, f
Dim wb As Workbook, i As Integer
FileNameXls = Application.GetOpenFilename(filefilter:="Excel Files, *.xl*", MultiSelect:=True)
If Not IsArray(FileNameXls) Then Exit Sub
For Each f In FileNameXls
Set wb = Workbooks.Open(f)
If ThisWorkbook.Sheets("Sheet1").Cells(11, 6).Value = 0 Then
ThisWorkbook.Sheets("Sheet1").Cells(11, 6).Formula = "=[" & wb.Name & "]Sheet1!" & Cell(11, 6).Name
Else
ThisWorkbook.Sheets("Sheet1").Cells(11, 6).Formula = "=[" & ThisWorkbook.Name & "]Sheet1!" & Cell(11, 6).Name & " + [" & wb.Name & "]Sheet1!" & Cell(11, 6).Name
End If
wb.Close SaveChanges:=False
Next f
End Sub
Well, normally a reference to cell F10 of Sheet1 of Book2 is expressed like this in a formula:
=[Book2]Sheet1!$F$10
Is it possible for you to reference the Sheet NAME instead of the NUMBER?
If yes, the first of your assignments should look like this:
ThisWorkbook.Sheets(9).Cells(11, 6).Formula = "=[" & wb.Name & "]Sheet1!$F$10"
Where Sheet1 is of course the name of your Sheets(9)

Is it possible to change number formats of 4 columns of a row based on a text value in that row for a range of rows?

I'm in a bad spot - any help pointing me in the right direction would be helpful and much appreciated.
I've created a Access process that copies an excel file and updates it with data from 2 record sets using Copy Recordset. The process now creates 39 workbooks by copying a 'template workbook' to a new file. Each workbook will contain at least one tab, but generally contain more, one workbook has over 20 tabs.
This is all done in Access. It copies the 'template' file and then runs a loop, and using Copy Recordset copies the 'template' worksheet to each tab.
After adding the tab, it loads the data from 2 record sets into the sheet. The 1st recordset loads one row of data - no problem. However the second loads multiple rows - which can vary in number.
This all works fine. The problem is formatting columns D through G.
If Column C = Revenue, Cost or Gross Margin (GM) I want that row's columns D through G formatted as currency.
If Column C = GM% then I want columns D through G formatted as a percentage.
If column C = Hours I don't have to format it.
What I would like is to create a function that formats these columns/rows based on Column C value, when the workbook is opened. I know there is an event that fires when the workbook is opened, and I know I have looped through all of the tabs in a workbook, o I'd want to run that function for each tab.
There may be one other issue - I think I can fix that in Access, but the EAC column is being exported as text and it should numeric. Not sure right now if that's being exported as Text - or EXCEL sees it as text.
Any help would be greatly appreciated. Thanks in advance.
I have images - but it won't let me post them just yet. If they would help - let me know, I'll try to email them to you.
Bob
I've come up with a way to do it, I've included the code.
However there may be a better way - so I'm open to suggestions.
Public Sub FormatTaskRows()
Dim Sheet As Object
Dim rngTasks As Range
Dim rngFCells As Range
Dim strTaskEnd As String
Dim ix As Integer
For Each Sheet In Sheets
If Sheet.Name = "Template" Then
Sheet.Visible = xlSheetVeryHidden
Else
Sheet.Visible = xlSheetVisible
Sheet.Activate
strTaskEnd = Range("C44").End(xlDown).Address
Set rngTasks = Range("$C$44:" & strTaskEnd)
'For Each Row In rngTasks
For ix = 1 To rngTasks.Rows.Count
Sheet.Unprotect
If rngTasks.Cells(ix) = "Revenue" Or rngTasks.Cells(ix) = "Cost" Or rngTasks.Cells(ix) = "Gross Margin (GM)" Then
Set rngFCells = Range(ActiveSheet.Name & "!D" & ix + 43 & ":G" & ix + 43)
rngFCells.Select
Selection.NumberFormat = "$#,##0.00"
Else
If rngTasks.Cells(ix) = "GM%" Then
Set rngFCells = Range(ActiveSheet.Name & "!D" & ix + 43 & ":G" & ix + 43)
rngFCells.Select
Selection.NumberFormat = "0.0000%"
End If
End If
Sheet.Protect
Next ix
End If
Next
End Sub

Copy & paste rows that match a condition when a button is pressed in another workbook

I am not an expert on VBA as I've recently started looking into this.
I wonder if the following is possible.
I have several workbooks with three worksheets (Old,Summary,New).
The condition is that all cells in column D with value H or M in worksheet with name New will indicate that the entire row would have to be copied to the worksheet with name Summary in the same workbook.
This mentioned above should have to happen when a button from another workbook is pressed and ideally the name of the file/workbook should be changeable so I can select what workbook do I want to run the macro.
Ideally the workbook with the data should not have any macro, all macros should be run from the second workbook with the button.
I would appreciate an example code with comments (so I can learn) if this is possible and not too complicated.
Please don't hesitate on making any questions if something is unclear...
UPDATE
Here is the macro I manage to compose looking at different codes
Sub CopyPaste()
Set NewWorkPlan = Sheets("New Workplan")
Set NewExecSummary = Sheets("New Exec Summary")
Dim d
Dim j
d = 1
j = 2
Do Until j = 200
If NewWorkPlan.Range("D" & j) = "M" Or NewWorkPlan.Range("D" & j) = "H" Then
d = d + 1
NewExecSummary.Rows(d).Value = NewWorkPlan.Rows(j).Value
End If
j = j + 1
'MsgBox (j)
Loop
End Sub
This works perfect for me, and to take it an step forward I'd like to be able to execute this from another workbook, leaving target workbook macro free.
The problem is that the workbook I want to run the macro is going to be shared and I don't think you can run macros.
Just change your references to the workbook you want and it should work fine (as long as the other workbook is open, though if it's not, you can open it from code also.
Reference:
Set NewExecSummary = Workbooks("TargetWorkbook").Sheets("New Exec Summary")

Resources